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.



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_pointObject

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_pointObject

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

#cloneObject



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

#distanceObject



35
36
37
# File 'lib/mittsu/math/line3.rb', line 35

def distance
  @start_point.distance_to(@end_point)
end

#distance_sqObject



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