Class: Mittsu::Line3
- Inherits:
-
Object
- Object
- Mittsu::Line3
- Defined in:
- lib/mittsu/math/line3.rb
Instance Attribute Summary collapse
-
#end_point ⇒ Object
Returns the value of attribute end_point.
-
#start_point ⇒ Object
Returns the value of attribute start_point.
Instance Method Summary collapse
- #apply_matrix4(matrix) ⇒ Object
- #at(t, target = Mittsu::Vector3.new) ⇒ Object
- #center(target = Mittsu::Vector3.new) ⇒ Object
- #clone ⇒ Object
- #closest_point_to_point(point, clamp_to_line, target = Mittsu::Vector3.new) ⇒ Object
- #closest_point_to_point_parameter(point, clamp_to_line) ⇒ Object
- #copy(line) ⇒ Object
- #delta(target = Mittsu::Vector3.new) ⇒ Object
- #distance ⇒ Object
- #distance_sq ⇒ Object
- #equals(line) ⇒ Object
-
#initialize(start_point = Mittsu::Vector3.new, end_point = Mittsu::Vector3.new) ⇒ Line3
constructor
A new instance of Line3.
- #set(start_point, end_point) ⇒ Object
Constructor Details
#initialize(start_point = Mittsu::Vector3.new, end_point = Mittsu::Vector3.new) ⇒ Line3
Returns a new instance of Line3.
7 8 9 |
# File 'lib/mittsu/math/line3.rb', line 7 def initialize(start_point = Mittsu::Vector3.new, end_point = Mittsu::Vector3.new) @start_point, @end_point = start_point, end_point end |
Instance Attribute Details
#end_point ⇒ Object
Returns the value of attribute end_point.
5 6 7 |
# File 'lib/mittsu/math/line3.rb', line 5 def end_point @end_point end |
#start_point ⇒ Object
Returns the value of attribute start_point.
5 6 7 |
# File 'lib/mittsu/math/line3.rb', line 5 def start_point @start_point end |
Instance Method Details
#apply_matrix4(matrix) ⇒ Object
62 63 64 65 66 |
# File 'lib/mittsu/math/line3.rb', line 62 def apply_matrix4(matrix) @start_point.apply_matrix4(matrix) @end_point.apply_matrix4(matrix) self end |
#at(t, target = Mittsu::Vector3.new) ⇒ Object
39 40 41 |
# File 'lib/mittsu/math/line3.rb', line 39 def at(t, target = Mittsu::Vector3.new) self.delta(target).multiply_scalar(t).add(self.start_point) end |
#center(target = Mittsu::Vector3.new) ⇒ Object
23 24 25 |
# File 'lib/mittsu/math/line3.rb', line 23 def center(target = Mittsu::Vector3.new) target.add_vectors(@start_point, @end_point).multiply_scalar(0.5) end |
#clone ⇒ Object
72 73 74 |
# File 'lib/mittsu/math/line3.rb', line 72 def clone Mittsu::Line3.new.copy(self) end |
#closest_point_to_point(point, clamp_to_line, target = Mittsu::Vector3.new) ⇒ Object
57 58 59 60 |
# File 'lib/mittsu/math/line3.rb', line 57 def closest_point_to_point(point, clamp_to_line, target = Mittsu::Vector3.new) t = self.closest_point_to_point_parameter(point, clamp_to_line) self.delta(target).multiply_scalar(t).add(self.start_point) end |
#closest_point_to_point_parameter(point, clamp_to_line) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/mittsu/math/line3.rb', line 43 def closest_point_to_point_parameter(point, clamp_to_line) start_p = Mittsu::Vector3.new start_end = Mittsu::Vector3.new start_p.sub_vectors(point, @start_point) start_end.sub_vectors(@end_point, @start_point) start_end2 = start_end.dot(start_end) start_end_start_p = start_end.dot(start_p) t = start_end_start_p / start_end2 if clamp_to_line t = Math.clamp(t, 0.0, 1.0) end t end |
#copy(line) ⇒ Object
17 18 19 20 21 |
# File 'lib/mittsu/math/line3.rb', line 17 def copy(line) @start_point.copy(line.start_point) @end_point.copy(line.end_point) self end |
#delta(target = Mittsu::Vector3.new) ⇒ Object
27 28 29 |
# File 'lib/mittsu/math/line3.rb', line 27 def delta(target = Mittsu::Vector3.new) target.sub_vectors(@end_point, @start_point) end |
#distance ⇒ Object
35 36 37 |
# File 'lib/mittsu/math/line3.rb', line 35 def distance @start_point.distance_to(@end_point) end |
#distance_sq ⇒ Object
31 32 33 |
# File 'lib/mittsu/math/line3.rb', line 31 def distance_sq @start_point.distance_to_squared(@end_point) end |
#equals(line) ⇒ Object
68 69 70 |
# File 'lib/mittsu/math/line3.rb', line 68 def equals(line) line.start_point.equals(@start_point) && line.end_point.equals(@end_point) end |
#set(start_point, end_point) ⇒ Object
11 12 13 14 15 |
# File 'lib/mittsu/math/line3.rb', line 11 def set(start_point, end_point) @start_point.copy(start_point) @end_point.copy(end_point) self end |