Class: GMath3D::FiniteLine
- Includes:
- BoxAvailable
- Defined in:
- lib/finite_line.rb
Overview
FiniteLine represents a finite line on 3D space.
Instance Attribute Summary collapse
-
#end_point ⇒ Object
Returns the value of attribute end_point.
-
#start_point ⇒ Object
Returns the value of attribute start_point.
Attributes inherited from Geom
Class Method Summary collapse
- .ary_distanc_to_point(finite_lines, target_point) ⇒ Object
- .ary_distance_to_line(finite_lines, target_line) ⇒ Object
Instance Method Summary collapse
-
#==(rhs) ⇒ Object
- Input
-
rhs should be FiniteLine.
-
#direction ⇒ Object
- Output
-
return direction as vector from start_point to end_point as Vector3.
-
#distance(target) ⇒ Object
This function returns closest distance between FiniteLine and anothor element.
-
#initialize(start_point = Vector3.new(0,0,0), end_point = Vector3.new(1,0,0)) ⇒ FiniteLine
constructor
- Input
-
start_point and end_point should be Vector3.
- #initialize_copy(original_obj) ⇒ Object
-
#length ⇒ Object
- Output
-
return length as Numeric.
-
#point(parameter) ⇒ Object
- Input
-
parameter should be Numeric.
-
#rotate(mat) ⇒ Object
- Input
-
mat should be Matrix which row and col size are 3.
- #to_s ⇒ Object
-
#vertices ⇒ Object
- Output
-
return Array of start_point and end_point.
Methods included from BoxAvailable
Methods inherited from Geom
Constructor Details
#initialize(start_point = Vector3.new(0,0,0), end_point = Vector3.new(1,0,0)) ⇒ FiniteLine
- Input
-
start_point and end_point should be Vector3.
- Output
-
return new instance as FiniteLine
18 19 20 21 22 23 24 |
# File 'lib/finite_line.rb', line 18 def initialize(start_point = Vector3.new(0,0,0), end_point = Vector3.new(1,0,0)) Util3D.check_arg_type(Vector3, start_point) Util3D.check_arg_type(Vector3, end_point) super() @start_point = start_point @end_point = end_point end |
Instance Attribute Details
#end_point ⇒ Object
Returns the value of attribute end_point.
10 11 12 |
# File 'lib/finite_line.rb', line 10 def end_point @end_point end |
#start_point ⇒ Object
Returns the value of attribute start_point.
9 10 11 |
# File 'lib/finite_line.rb', line 9 def start_point @start_point end |
Class Method Details
.ary_distanc_to_point(finite_lines, target_point) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/finite_line.rb', line 111 def self.ary_distanc_to_point(finite_lines, target_point) Util3D.check_arg_type(::Array, finite_lines) Util3D.check_arg_type(Vector3, target_point) distance_ary = Array.new(0) points_ary = Array.new(0) finite_lines.each do | item | distance, point = item.distance(target_point) distance_ary.push(distance); points_ary.push(point) end distance = distance_ary.min closest_point = points_ary[distance_ary.index(distance)] return distance, closest_point end |
.ary_distance_to_line(finite_lines, target_line) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/finite_line.rb', line 126 def self.ary_distance_to_line(finite_lines, target_line) Util3D.check_arg_type(::Array, finite_lines) Util3D.check_arg_type(Line, target_line) distance_ary = Array.new(0) point_on_target_ary = Array.new(0) point_on_finite_line_ary = Array.new(0) param_on_target_ary = Array.new(0) param_on_finite_line_ary = Array.new(0) finite_lines.each do | item | distance, point_on_myself, point_on_target, parameter_on_myself, parameter_on_tatget = item.distance(target_line) distance_ary.push(distance) point_on_target_ary.push(point_on_target) point_on_finite_line_ary.push(point_on_myself) param_on_target_ary.push(parameter_on_tatget) param_on_finite_line_ary.push(parameter_on_myself) end distance = distance_ary.min point_on_finiteline = point_on_finite_line_ary[distance_ary.index(distance)] point_on_target = point_on_target_ary[distance_ary.index(distance)] param_on_finiteline = param_on_finite_line_ary[distance_ary.index(distance)] param_on_target = param_on_target_ary[distance_ary.index(distance)] return distance, point_on_finiteline, point_on_target, param_on_finiteline, param_on_target end |
Instance Method Details
#==(rhs) ⇒ Object
- Input
-
rhs should be FiniteLine.
- Output
-
return true if rhs equals myself.
49 50 51 52 53 54 55 |
# File 'lib/finite_line.rb', line 49 def ==(rhs) return false if rhs == nil return false if !rhs.kind_of?(FiniteLine) return false if( self.start_point != rhs.start_point) return false if( self.end_point != rhs.end_point) return true end |
#direction ⇒ Object
- Output
-
return direction as vector from start_point to end_point as Vector3
65 66 67 |
# File 'lib/finite_line.rb', line 65 def direction @end_point - @start_point end |
#distance(target) ⇒ Object
This function returns closest distance between FiniteLine and anothor element.
- Input
-
target should be Vector3 or Line or FiniteLine
- Output
- in case target is Vector3
-
return “distance, closest point on myself, parameter on myself” as [Numeric, Vector3, Numeric]
- in case target is Line or FiniteLine
-
return “distance, point on myself, point on target, parameter on myself, parameter on tatget” as [Numeric, Vector3, Vector3, Numeric, Numeric]
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/finite_line.rb', line 97 def distance(target) # with Point if(target.kind_of?(Vector3)) return distance_to_point(target) #with Line elsif(target.kind_of?(Line)) return distance_to_line(target) #widh Finite Line elsif(target.kind_of?(FiniteLine)) return distance_to_finite_line(target) end Util3D.raise_argurment_error(target) end |
#initialize_copy(original_obj) ⇒ Object
26 27 28 29 |
# File 'lib/finite_line.rb', line 26 def initialize_copy( original_obj ) @start_point = original_obj.start_point.dup @end_point = original_obj.end_point.dup end |
#length ⇒ Object
- Output
-
return length as Numeric
83 84 85 |
# File 'lib/finite_line.rb', line 83 def length @start_point.distance(@end_point) end |
#point(parameter) ⇒ Object
- Input
-
parameter should be Numeric.
- Output
-
return a point on line at input parameter position as Vector3
73 74 75 76 77 78 79 |
# File 'lib/finite_line.rb', line 73 def point(parameter) if(parameter < 0.0 or 1.0 < parameter) return nil else return @start_point * (1.0 - parameter) + @end_point * parameter end end |
#rotate(mat) ⇒ Object
- Input
-
mat should be Matrix which row and col size are 3.
- Output
-
return rotated FiniteLine.
39 40 41 42 43 |
# File 'lib/finite_line.rb', line 39 def rotate(mat) rot_start_point = mat*start_point rot_end_point = mat*end_point return FiniteLine.new(rot_start_point, rot_end_point) end |
#to_s ⇒ Object
31 32 33 |
# File 'lib/finite_line.rb', line 31 def to_s "FiniteLine[from#{start_point.to_element_s}, to#{end_point.to_element_s}]" end |
#vertices ⇒ Object
- Output
-
return Array of start_point and end_point.
59 60 61 |
# File 'lib/finite_line.rb', line 59 def vertices return [start_point, end_point] end |