Ray Tracing Intersection
Description:
Ray tracing is technique for generating an image by calculating the path of rays of light through a scene of objects. Rays are cast from an eye point through a frame and into a scene. The intersection of each ray with an object (or no object at all) in the scene determines the color of the pixel in the frame through which the ray passed. A ray consists of a point and a vector.
data Ray3 = Ray3 Pt3 Vec3
A object is a datatype which is an implements the hit
function from the shape typeclass. hit
returns a Maybe because the ray may not hit the object at all.
class Shape s where
hit :: Ray3 -> s -> Maybe HitRecord
The only objects we will cover are spheres. A sphere has a center and a radius.
data Sphere = Sphere Pt3 Double
Write a function hit
that, given a ray and a datatype that implements Shape
, calculates the time, point, and surface normal at which the ray hit the nearest object, if the ray hit any objects at all. This information is bundled up in a HitRecord
datatype.
data HitRecord = HitRecord (Pt3 Double) (Vec3 Double) Double
The Pt3
indicates the position in the coordinate system in which the ray intersected the shape, the Vec3
indicates the vector normal (perpendicular) to the surface of the shape at the intersection point. The double
field indicates the time at which the ray intersected the shape (the direction of the ray scaled by the time should equal the intersection point minus the base of the ray).
Resources:
A brief overview of ray tracing and ray-sphere intersections: Graphics for the masses
A more comprehensive ray tracing overview: Fundamentals of Computer Graphics
Similar Kata:
Stats:
Created | Oct 24, 2014 |
Warriors Trained | 11 |
Total Skips | 0 |
Total Code Submissions | 5 |
Total Times Completed | 1 |
Haskell Completions | 1 |
Total Stars | 2 |
% of votes with a positive feedback rating | 0% of 0 |
Total "Very Satisfied" Votes | 0 |
Total "Somewhat Satisfied" Votes | 0 |
Total "Not Satisfied" Votes | 0 |