Class: GMath3D::Rectangle
- Includes:
- BoxAvailable
- Defined in:
- lib/rectangle.rb
Overview
Rectangle represents a four edged finite plane on 3D space.
Instance Attribute Summary collapse
-
#base_point ⇒ Object
Returns the value of attribute base_point.
-
#u_vector ⇒ Object
Returns the value of attribute u_vector.
-
#v_vector ⇒ Object
Returns the value of attribute v_vector.
Attributes inherited from Geom
Instance Method Summary collapse
-
#==(rhs) ⇒ Object
- Input
-
rhs is Rectangle.
-
#area ⇒ Object
- Output
-
return rectangle area as Numeric.
-
#center_point ⇒ Object
- Output
-
return center point as Vector3.
-
#distance(target) ⇒ Object
- Input
-
target shold be Vector3.
-
#edges ⇒ Object
- Output
-
return edges of rectangle as Array of FiniteLine.
-
#initialize(base_point_arg = Vector3.new(), u_vector_arg = Vector3.new(1,0,0), v_vector_arg = Vector3.new(0,1,0)) ⇒ Rectangle
constructor
- Input
-
base_point , u_vector, v_vector should be Vector3.
- #initialize_copy(original_obj) ⇒ Object
-
#normal ⇒ Object
- Output
-
return normal of rectangle as Vector3.
-
#opposite_point ⇒ Object
- Output
-
return point of opposite to base_point as Vector3.
-
#point(u, v) ⇒ Object
- Input
-
u, v should be Numeric.
- #to_s ⇒ Object
-
#uv_parameter(check_point) ⇒ Object
- Input
-
check_point shold be Vector3.
-
#vertices ⇒ Object
- Output
-
return vertices of rectangle as Array of Vector3.
Methods included from BoxAvailable
Methods inherited from Geom
Constructor Details
#initialize(base_point_arg = Vector3.new(), u_vector_arg = Vector3.new(1,0,0), v_vector_arg = Vector3.new(0,1,0)) ⇒ Rectangle
- Input
-
base_point , u_vector, v_vector should be Vector3.
u_vector and v_vector should be orthogonalized.
- Output
-
return new instance of Rectangle.
22 23 24 25 26 27 28 29 30 |
# File 'lib/rectangle.rb', line 22 def initialize(base_point_arg = Vector3.new(), u_vector_arg = Vector3.new(1,0,0), v_vector_arg = Vector3.new(0,1,0)) Util3D.check_arg_type(::Vector3, base_point_arg) Util3D.check_arg_type(::Vector3, u_vector_arg) Util3D.check_arg_type(::Vector3, v_vector_arg) super() self.base_point = base_point_arg self.u_vector = u_vector_arg self.v_vector = v_vector_arg end |
Instance Attribute Details
#base_point ⇒ Object
Returns the value of attribute base_point.
11 12 13 |
# File 'lib/rectangle.rb', line 11 def base_point @base_point end |
#u_vector ⇒ Object
Returns the value of attribute u_vector.
12 13 14 |
# File 'lib/rectangle.rb', line 12 def u_vector @u_vector end |
#v_vector ⇒ Object
Returns the value of attribute v_vector.
13 14 15 |
# File 'lib/rectangle.rb', line 13 def v_vector @v_vector end |
Instance Method Details
#==(rhs) ⇒ Object
- Input
-
rhs is Rectangle.
- Output
-
return true if rhs equals myself.
42 43 44 45 46 47 48 49 |
# File 'lib/rectangle.rb', line 42 def ==(rhs) return false if rhs == nil return false if( !rhs.kind_of?(Rectangle) ) return false if( self.base_point != rhs.base_point) return false if( self.u_vector != rhs.u_vector) return false if( self.v_vector != rhs.v_vector) return true end |
#area ⇒ Object
- Output
-
return rectangle area as Numeric.
107 108 109 |
# File 'lib/rectangle.rb', line 107 def area return (u_vector.cross(v_vector)).length end |
#center_point ⇒ Object
- Output
-
return center point as Vector3.
101 102 103 |
# File 'lib/rectangle.rb', line 101 def center_point return base_point + u_vector*0.5 + v_vector*0.5 end |
#distance(target) ⇒ Object
- Input
-
target shold be Vector3.
- Output
-
return “distance, point on rectangle” as [Numeric, Vector3].
129 130 131 132 133 134 135 136 137 138 |
# File 'lib/rectangle.rb', line 129 def distance(target) # with Point if(target.kind_of?(Vector3)) return distance_to_point(target) elsif(target.kind_of?(Line)) #with Line # return distance_to_line(target) end Util3D.raise_argurment_error(target) end |
#edges ⇒ Object
- Output
-
return edges of rectangle as Array of FiniteLine.
67 68 69 70 71 72 73 74 |
# File 'lib/rectangle.rb', line 67 def edges edge_ary = Array.new(4) edge_ary[0] = FiniteLine.new( base_point, base_point+u_vector) edge_ary[1] = FiniteLine.new( base_point+u_vector, base_point+u_vector+v_vector) edge_ary[2] = FiniteLine.new( base_point+u_vector+v_vector, base_point+v_vector) edge_ary[3] = FiniteLine.new( base_point+v_vector, base_point) return edge_ary end |
#initialize_copy(original_obj) ⇒ Object
32 33 34 35 36 |
# File 'lib/rectangle.rb', line 32 def initialize_copy( original_obj ) @base_point = original_obj.base_point.dup @u_vector = original_obj.u_vector.dup @v_vector = original_obj.v_vector.dup end |
#normal ⇒ Object
- Output
-
return normal of rectangle as Vector3.
89 90 91 |
# File 'lib/rectangle.rb', line 89 def normal return (u_vector.cross(v_vector)).normalize() end |
#opposite_point ⇒ Object
- Output
-
return point of opposite to base_point as Vector3.
95 96 97 |
# File 'lib/rectangle.rb', line 95 def opposite_point return base_point + u_vector + v_vector end |
#point(u, v) ⇒ Object
- Input
-
u, v should be Numeric.
- Output
-
return point on rectangle as Vector3.
59 60 61 62 63 |
# File 'lib/rectangle.rb', line 59 def point(u, v) Util3D.check_arg_type(::Numeric, u) Util3D.check_arg_type(::Numeric, v) return base_point + u_vector*u + v_vector*v end |
#to_s ⇒ Object
51 52 53 |
# File 'lib/rectangle.rb', line 51 def to_s "Rectangle[base#{@base_point.to_element_s}, u#{@u_vector.to_element_s}, v#{@v_vector.to_element_s}" end |
#uv_parameter(check_point) ⇒ Object
- Input
-
check_point shold be Vector3.
- Output
-
return u, v parametes on check_point as [Numeric, Numeric].
115 116 117 118 119 120 121 122 123 |
# File 'lib/rectangle.rb', line 115 def uv_parameter(check_point) Util3D.check_arg_type(::Vector3, check_point) mat = Matrix[[u_vector.x, u_vector.y, u_vector.z], [v_vector.x, v_vector.y, v_vector.z], [normal.x, normal.y, normal.z]] vec = (check_point - base_point).to_column_vector ans = mat.t.inv*vec return ans[0,0], ans[1,0] end |
#vertices ⇒ Object
- Output
-
return vertices of rectangle as Array of Vector3.
78 79 80 81 82 83 84 85 |
# File 'lib/rectangle.rb', line 78 def vertices vertices = Array.new(4) vertices[0] = base_point vertices[1] = base_point+u_vector vertices[2] = base_point+u_vector+v_vector vertices[3] = base_point+v_vector return vertices end |