class Sphere
Attributes
point[RW]
radius[RW]
Public Class Methods
new(point, radius)
click to toggle source
# File lib/geometry_3d/sphere.rb, line 5 def initialize(point, radius) @point = point @radius = radius end
Public Instance Methods
circumference()
click to toggle source
Find the circumference of a sphere.
Example:
>> Sphere.new(Point.new(1, 2, 3), 3).circumference => 18.84955592153876
Arguments:
no
# File lib/geometry_3d/sphere.rb, line 45 def circumference Circle.new(radius).perimeter end
intersect?(sphere)
click to toggle source
Checks if two spheres intersect/
Example:
>> Sphere.new(Point.new(-7, -4, 3), 20).intersect?(Sphere.new(Point.new(17, 6, 2.5), 7)) => true
Arguments:
no
# File lib/geometry_3d/sphere.rb, line 58 def intersect?(sphere) point.distance_to_point(sphere.point) <= (radius + sphere.radius) end
surface_area()
click to toggle source
Find the surface area of a sphere.
Example:
>> Sphere.new(Point.new(1, 2, 3), 3).surface_area => 113.09733552923254
Arguments:
no
# File lib/geometry_3d/sphere.rb, line 19 def surface_area 4 * Math::PI * radius ** 2 end
volume()
click to toggle source
Find the volume of a sphere.
Example:
>> Sphere.new(Point.new(1, 2, 3), 3).volume => 113.09733552923254
Arguments:
no
# File lib/geometry_3d/sphere.rb, line 32 def volume (4.0 / 3) * Math::PI * radius ** 3 end