Class: Ra::Shape::Sphere
Overview
A sphere at origin <0,0,0> with a radius 1. A sphere surface is defined:
x² + y² + z² = radius²
A unit radius simplifies further:
x² + y² + z² = 1
A ray x / y / z values at t use the origin and direction:
x = origin.x + direction.x * t
y = origin.y + direction.y * t
z = origin.z + direction.z * t
Substituting x / y / z allows for solving for t:
1 = (origin.x + direction.x * t)²
+ (origin.y + direction.y * t)²
+ (origin.z + direction.z * t)²
Simplifying gives us a quadratic formula with terms defined as:
a = direction.x² + direction.y² + direction.z²
b = 2 * ((origin.x * direction.x) + (origin.y * direction.y) + (origin.z * direction.z))
c = origin.x² + origin.y² + origin.z² - 1
discriminant = b² - 4ac
t = (-b ± √discriminant) / (2a)
A discriminant <0 indicates the ray does not intersect the sphere.
Instance Attribute Summary
Attributes inherited from Base
Method Summary
Methods inherited from Base
#color, #initialize, #intersect, #normal
Constructor Details
This class inherits a constructor from Ra::Shape::Base