class Mittsu::Sphere
Attributes
center[RW]
radius[RW]
Public Class Methods
new(center = Mittsu::Vector3.new, radius = 0.0)
click to toggle source
# File lib/mittsu/math/sphere.rb, line 5 def initialize(center = Mittsu::Vector3.new, radius = 0.0) @center, @radius = center, radius.to_f end
Public Instance Methods
==(sphere)
click to toggle source
# File lib/mittsu/math/sphere.rb, line 81 def ==(sphere) sphere.center == (@center) && sphere.radius == @radius end
apply_matrix4(matrix)
click to toggle source
# File lib/mittsu/math/sphere.rb, line 70 def apply_matrix4(matrix) @center.apply_matrix4(matrix) @radius = @radius * matrix.max_scale_on_axis self end
bounding_box(target = Mittsu::Box3.new)
click to toggle source
# File lib/mittsu/math/sphere.rb, line 64 def bounding_box(target = Mittsu::Box3.new) target.set(@center, @center) target.expand_by_scalar(@radius) target end
clamp_point(point, target = Mittsu::Vector3.new)
click to toggle source
# File lib/mittsu/math/sphere.rb, line 54 def clamp_point(point, target = Mittsu::Vector3.new) delta_length_sq = @center.distance_to_squared(point) target.copy(point) if delta_length_sq > (@radius * @radius) target.sub(@center).normalize target.multiply_scalar(@radius).add(@center) end target end
clone()
click to toggle source
# File lib/mittsu/math/sphere.rb, line 85 def clone Mittsu::Sphere.new.copy(self) end
contains_point?(point)
click to toggle source
# File lib/mittsu/math/sphere.rb, line 41 def contains_point?(point) point.distance_to_squared(@center) <= @radius * @radius end
copy(sphere)
click to toggle source
# File lib/mittsu/math/sphere.rb, line 31 def copy(sphere) @center.copy(sphere.center) @radius = sphere.radius self end
distance_to_point(point)
click to toggle source
# File lib/mittsu/math/sphere.rb, line 45 def distance_to_point(point) point.distance_to(@center) - @radius end
empty()
click to toggle source
# File lib/mittsu/math/sphere.rb, line 37 def empty @radius <= 0 end
intersects_sphere?(sphere)
click to toggle source
# File lib/mittsu/math/sphere.rb, line 49 def intersects_sphere?(sphere) radiusSum = @radius + sphere.radius sphere.center.distance_to_squared(@center) <= radiusSum * radiusSum end
set(center, radius)
click to toggle source
# File lib/mittsu/math/sphere.rb, line 9 def set(center, radius) @center.copy(center) @radius = radius.to_f self end
set_from_points(points, optional_center = nil)
click to toggle source
# File lib/mittsu/math/sphere.rb, line 15 def set_from_points(points, optional_center = nil) box = Mittsu::Box3.new c = @center if optional_center.nil? box.set_from_points(points).center(c) else c.copy(optional_center) end max_radius_sq = 0.0 points.each do |point| max_radius_sq = [max_radius_sq, c.distance_to_squared(point)].max end @radius = ::Math.sqrt(max_radius_sq) self end
translate(offset)
click to toggle source
# File lib/mittsu/math/sphere.rb, line 76 def translate(offset) @center.add(offset) self end