lib/vector3.rb in gmath3D-0.2.2 vs lib/vector3.rb in gmath3D-0.2.3

- old
+ new

@@ -1,5 +1,6 @@ +# -*- coding: cp932 -*- require 'gmath3D' module GMath3D # # Vector3 represents a point or a vector on 3D space. @@ -47,10 +48,16 @@ end def eql?(rhs) equals_inner(rhs) end + # [Output] + # return axially aligned bounding box as Box. + def box + return Box.new(self, self) + end + # [Input] # _rhs_ should be Vector3. # [Output] # return added result as Vector3. def +(rhs) @@ -98,9 +105,26 @@ Util.check_arg_type(Vector3, rhs) Vector3.new( self.y*rhs.z - self.z*rhs.y, self.z*rhs.x - self.x*rhs.z, self.x*rhs.y - self.y*rhs.x) + end + + # [Output] + # return orthogonal vector as Vector3. + def arbitrary_orthogonal + return Vector3.new() if(self.length < self.tolerance) + + if(!self.parallel?( Vector3.new(0.0, 1.0, 0.0) )) + un_parallel_vec = Vector3.new(0.0,1.0,0.0) + elsif(!self.parallel?( Vector3.new(0.0,0.0,1.0) )) + un_parallel_vec = Vector3.new(0.0,0.0,1.0) + else + un_parallel_vec = Vector3.new(1.0,0.0,0.0) + end + + orthogonal = self.cross(un_parallel_vec) + return orthogonal.normalize end # [Output] # return vector length as Numeric def length