Advertisement
cd62131

normalize vector product

Nov 1st, 2018
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.27 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. module NormalVector
  3.   refine Array do
  4.     def normal(o)
  5.       require 'matrix'
  6.       Vector.elements(self.map &:to_f)
  7.       .cross(Vector.elements(o))
  8.       .normalize.to_a
  9.     end
  10.   end
  11. end
  12. using NormalVector
  13. puts "#{[1, 2, 3].normal [4, 5, 6]}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement