lib/triangle.rb in gmath3D-0.2.1 vs lib/triangle.rb in gmath3D-0.2.2
- old
+ new
@@ -18,10 +18,31 @@
Util.check_arg_type(::Vector3, vertex3)
super()
@vertices = Array.new([vertex1, vertex2, vertex3])
end
+ def initialize_copy( original_obj )
+ @vertices = Array.new(original_obj.vertices.size)
+ for i in 0..@vertices.size-1
+ @vertices[i] = original_obj.vertices[i].dup
+ end
+ end
+
+ # [Input]
+ # _rhs_ is Line.
+ # [Output]
+ # return true if rhs equals myself.
+ def ==(rhs)
+ return false if rhs == nil
+ return false if( !rhs.kind_of?(Triangle) )
+ return false if(@vertices.size != rhs.vertices.size)
+ for i in 0..@vertices.size-1
+ return false if(@vertices[i] != rhs.vertices[i])
+ end
+ return true
+ end
+
def to_s
"Triangle[#{@vertices[0].to_element_s}, #{@vertices[1].to_element_s}, #{@vertices[2].to_element_s}]"
end
# [Input]
@@ -63,9 +84,15 @@
# return normal vector as Vector3.
def normal
vec1 = self.vertices[1] - self.vertices[0]
vec2 = self.vertices[2] - self.vertices[0]
return (vec1.cross(vec2).normalize)
+ end
+
+ # [Output]
+ # return normal vector reversed triangle
+ def reverse()
+ return Triangle.new(@vertices[0], @vertices[2], @vertices[1])
end
# [Input]
# _check_point_ should be Vector3.
# [Output]