lib/quat.rb in gmath3D-0.2.1 vs lib/quat.rb in gmath3D-0.2.2
- old
+ new
@@ -144,11 +144,11 @@
t2 *= self.w
tf = t1 + t2 + t3
rtn_w = self.w * rhs.w - dot
- return Quat.new(tf.x, tf.y, tf.z, rtn_w).normalize
+ return Quat.new(tf.x, tf.y, tf.z, rtn_w)
end
# [Input]
# _rsh_ should be Quat.
# [Output]
@@ -163,141 +163,8 @@
x = pw * qx + px * qw + py * qz - pz * qy
y = pw * qy - px * qz + py * qw + pz * qx
z = pw * qz + px * qy - py * qx + pz * qw
return Quat.new( x,y,z,w )
end
-
-=begin
- # [Input]
- # _rhs_ should be Vector3.
- # [Output]
- # return subtracted result as Vector3.
- def -(rhs)
- subtract(rhs)
- end
-
-
- # [Input]
- # _rhs_ should be Numeric.
- # [Output]
- # return divided result as Vector3.
- def /(rhs)
- divide(rhs)
- end
-
- # [Input]
- # _rhs_ should be Vector3.
- # [Output]
- # return inner product as Numeric
- def dot(rhs)
- Util.check_arg_type(Vector3, rhs)
- self.x*rhs.x + self.y*rhs.y + self.z*rhs.z
- end
-
- # [Input]
- # _rhs_ should be Vector3.
- # [Output]
- # return cross product as Vector3.
- def cross(rhs)
- 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 vector length as Numeric
- def length
- Math::sqrt(self.x*self.x + self.y*self.y + self.z*self.z)
- end
-
- # [Input]
- # _rhs_ should be Vector3.
- # [Output]
- # return distance between two points as Numeric.
- def distance(rhs)
- Util.check_arg_type(Vector3, rhs)
- Math::sqrt((self.x - rhs.x)*(self.x - rhs.x) + (self.y - rhs.y)*(self.y - rhs.y) + (self.z - rhs.z)*(self.z - rhs.z))
- end
-
- # [Input]
- # _rhs_ should be Vector3.
- # [Output]
- # return two vectors angle as Numeric (rad).
- def angle(rhs)
- Util.check_arg_type(Vector3, rhs)
- vec1Length = self.length ;
- vec2Length = rhs.length ;
- return 0.0 if(vec1Length*vec2Length < self.tolerance )
- v = self.dot(rhs)/(vec1Length*vec2Length)
- Math::acos( v )
- end
-
- # [Output]
- # return normalized vector as Vector3
- def normalize()
- self / self.length.to_f
- end
-
- # [Input]
- # _rhs_ should be Vector3
- # [Output]
- # return true if myself and rhs is parallel as boolean
- def parallel?(rhs)
- Util.check_arg_type(Vector3, rhs)
- return false if(self.length < self.tolerance or rhs.length < rhs.tolerance)
- return false if(self.cross(rhs).length > self.tolerance)
- return true
- end
-
- # [Input]
- # _rhs_ should be Vector3.
- # [Output]
- # return true if myself and rhs have same direction as boolean.
- def same_direction?(rhs)
- Util.check_arg_type(Vector3, rhs)
- return false if(!parallel?(rhs))
- return false if(self.dot(rhs) < self.tolerance)
- return true
- end
-
- # This function projects self vector to rhs vector.
- # [Input]
- # _rhs_ should be Vector3.
- # [Output]
- # return projected result as Vector3.
- def project_to(rhs)
- Util.check_arg_type(Vector3, rhs)
- return Vector3.new, 0.0 if( rhs.length < rhs.tolerance )
- parameter = self.dot( rhs ) / ( rhs.x * rhs.x + rhs.y * rhs.y + rhs.z * rhs.z ).to_f
- return rhs*parameter, parameter
- end
-
- # [Output]
- # return column vector as Matrix
- def to_column_vector
- return Matrix.column_vector([x,y,z])
- end
-
- private
-
- def add(rhs)
- Util.check_arg_type(Vector3, rhs)
- Vector3.new(self.x + rhs.x, self.y + rhs.y, self.z + rhs.z)
- end
- def subtract(rhs)
- Util.check_arg_type(Vector3, rhs)
- Vector3.new(self.x - rhs.x, self.y - rhs.y, self.z - rhs.z)
- end
- def multiply(rhs)
- Util.check_arg_type(::Numeric, rhs)
- Vector3.new(self.x * rhs, self.y * rhs, self.z * rhs)
- end
- def divide(rhs)
- Util.check_arg_type(::Numeric, rhs)
- Vector3.new(self.x.to_f / rhs, self.y / rhs.to_f, self.z / rhs.to_f)
- end
-=end
end
end