Draft

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

Geometry
Graphics

Similar Kata:

More By Author:

Check out these other kata created by ninjasmodyurt

Stats:

CreatedOct 24, 2014
Warriors Trained11
Total Skips0
Total Code Submissions5
Total Times Completed1
Haskell Completions1
Total Stars2
% of votes with a positive feedback rating0% of 0
Total "Very Satisfied" Votes0
Total "Somewhat Satisfied" Votes0
Total "Not Satisfied" Votes0
Ad
Contributors
  • ninjasmodyurt Avatar
Ad