Class: Mittsu::Line3

Inherits:
Object
  • Object
show all
Defined in:
lib/mittsu/math/line3.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_point = Mittsu::Vector3.new, end_point = Mittsu::Vector3.new) ⇒ Line3

Returns a new instance of Line3.



5
6
7
# File 'lib/mittsu/math/line3.rb', line 5

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_pointObject

Returns the value of attribute end_point.



3
4
5
# File 'lib/mittsu/math/line3.rb', line 3

def end_point
  @end_point
end

#start_pointObject

Returns the value of attribute start_point.



3
4
5
# File 'lib/mittsu/math/line3.rb', line 3

def start_point
  @start_point
end

Instance Method Details

#apply_matrix4(matrix) ⇒ Object



60
61
62
63
64
# File 'lib/mittsu/math/line3.rb', line 60

def apply_matrix4(matrix)
  @start_point.apply_matrix4(matrix)
  @end_point.apply_matrix4(matrix)
  self
end

#at(t, target = Mittsu::Vector3.new) ⇒ Object



37
38
39
# File 'lib/mittsu/math/line3.rb', line 37

def at(t, target = Mittsu::Vector3.new)
  self.delta(target).multiply_scalar(t).add(self.start_point)
end

#center(target = Mittsu::Vector3.new) ⇒ Object



21
22
23
# File 'lib/mittsu/math/line3.rb', line 21

def center(target = Mittsu::Vector3.new)
  target.add_vectors(@start_point, @end_point).multiply_scalar(0.5)
end

#cloneObject



70
71
72
# File 'lib/mittsu/math/line3.rb', line 70

def clone
  Mittsu::Line3.new.copy(self)
end

#closest_point_to_point(point, clamp_to_line, target = Mittsu::Vector3.new) ⇒ Object



55
56
57
58
# File 'lib/mittsu/math/line3.rb', line 55

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



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/mittsu/math/line3.rb', line 41

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



15
16
17
18
19
# File 'lib/mittsu/math/line3.rb', line 15

def copy(line)
  @start_point.copy(line.start_point)
  @end_point.copy(line.end_point)
  self
end

#delta(target = Mittsu::Vector3.new) ⇒ Object



25
26
27
# File 'lib/mittsu/math/line3.rb', line 25

def delta(target = Mittsu::Vector3.new)
  target.sub_vectors(@end_point, @start_point)
end

#distanceObject



33
34
35
# File 'lib/mittsu/math/line3.rb', line 33

def distance
  @start_point.distance_to(@end_point)
end

#distance_sqObject



29
30
31
# File 'lib/mittsu/math/line3.rb', line 29

def distance_sq
  @start_point.distance_to_squared(@end_point)
end

#equals(line) ⇒ Object



66
67
68
# File 'lib/mittsu/math/line3.rb', line 66

def equals(line)
  line.start_point.equals(@start_point) && line.end_point.equals(@end_point)
end

#set(start_point, end_point) ⇒ Object



9
10
11
12
13
# File 'lib/mittsu/math/line3.rb', line 9

def set(start_point, end_point)
  @start_point.copy(start_point)
  @end_point.copy(end_point)
  self
end