class Mittsu::Line3

Attributes

end_point[RW]
start_point[RW]

Public Class Methods

new(start_point = Mittsu::Vector3.new, end_point = Mittsu::Vector3.new) click to toggle source
# 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

Public Instance Methods

apply_matrix4(matrix) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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
clone() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/mittsu/math/line3.rb, line 25
def delta(target = Mittsu::Vector3.new)
  target.sub_vectors(@end_point, @start_point)
end
distance() click to toggle source
# File lib/mittsu/math/line3.rb, line 33
def distance
  @start_point.distance_to(@end_point)
end
distance_sq() click to toggle source
# File lib/mittsu/math/line3.rb, line 29
def distance_sq
  @start_point.distance_to_squared(@end_point)
end
equals(line) click to toggle source
# 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) click to toggle source
# 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