| |||||||||||

| |||||||||||

| |||||||||||

Description | |||||||||||

This module contains functions for almost all the mathematical
concepts you will need to complete the assignment.
Vectors and Colours have been made instances of the
Num class so that you can add, subtract and multiply them where
this makes sense. For instance it does not make sense to multiply
Vectors and this will yield an error. You can only peform
a dot or cross product upon them. | |||||||||||

Synopsis | |||||||||||

New data types and type synonyms | |||||||||||

data PureObject | |||||||||||

| |||||||||||

data Object | |||||||||||

| |||||||||||

data Light | |||||||||||

| |||||||||||

newtype Point | |||||||||||

| |||||||||||

newtype Vector | |||||||||||

| |||||||||||

newtype Colour | |||||||||||

| |||||||||||

type Distance = Double | |||||||||||

type Time = Double | |||||||||||

data Ray | |||||||||||

| |||||||||||

Functions | |||||||||||

Core functionality | |||||||||||

intersect :: Ray -> PureObject -> Maybe (Time, Vector) | |||||||||||

interesect determines whether a light ray and object intersect and if so yields the time at which it intersects and a unit normal vector at the point of intersection. Returns Nothing if no interesection occurs. Note that intersection at negative times is possible. | |||||||||||

intersectPt :: Point -> PureObject -> Bool | |||||||||||

Checks whether a given Point intersects with a pure object | |||||||||||

vecToLight :: Point -> Light -> Vector | |||||||||||

vecToLight takes a Point and a light source and returns a
unit vector pointing towards the light source | |||||||||||

intensity :: Point -> Light -> Colour | |||||||||||

Takes a Point and a Light and returns the intensity at that
point. Simulates light attenuation over distance. | |||||||||||

Ray utilities | |||||||||||

rayAt :: Ray -> Time -> Point | |||||||||||

Takes a ray and a time parameter and yields the Point on the ray
at that time. | |||||||||||

rayOrigin :: Ray -> Point | |||||||||||

rayDir :: Ray -> Vector | |||||||||||

Vector utilities | |||||||||||

magnitude :: Vector -> Distance | |||||||||||

Determines the magnitude (or size) of a Vector | |||||||||||

dot :: Vector -> Vector -> Double | |||||||||||

Takes two vectors and yields their dot product | |||||||||||

vecFrom :: Point -> Point -> Vector | |||||||||||

Takes two Points and returns a Vector pointing from the first
point to the second one. The result is not necessarily a unit vector. | |||||||||||

scaleVec :: Double -> Vector -> Vector | |||||||||||

Pre-multiplies a vector by a scalar | |||||||||||

unit :: Vector -> Vector | |||||||||||

Takes a vector and returns one that has the same direction but is a unit vector | |||||||||||

angleBetween :: Vector -> Vector -> Double | |||||||||||

Calculates the angle between two unit vectors
It will give the wrong answer for non-unit vectors
If you are uncertain, apply unit to the arguments.
Angle is in radians between 0 and pi. This function will
not tell you whether the second vector is clockwise or anti-clockwise
from the first. | |||||||||||

distBetween :: Point -> Point -> Double | |||||||||||

The distance between two points | |||||||||||

rotateInPlane | |||||||||||

| |||||||||||

cross :: Vector -> Vector -> Vector | |||||||||||

Cross product of a Vector. Yields a Vector that is
is perpendicular to both arguments. Does not necessarily yield
a unit vector as a result. | |||||||||||

Colours | |||||||||||

scaleCol :: Double -> Colour -> Colour | |||||||||||

Pre-multiplies a Colour by a scalar | |||||||||||

Sample colours | |||||||||||

red :: Colour | |||||||||||

Brightest red | |||||||||||

green :: Colour | |||||||||||

Brightest green | |||||||||||

blue :: Colour | |||||||||||

Brightest blue | |||||||||||

black :: Colour | |||||||||||

Pure black | |||||||||||

white :: Colour | |||||||||||

Brightest white | |||||||||||

Miscellaneous functions | |||||||||||

doubleRes :: Double | |||||||||||

The resolution for doubles. If two doubles differ by less than this amount we consider them equal | |||||||||||

(==*) :: Double -> Double -> Bool | |||||||||||

Equality up to a given resolution (equal to doubleRes) | |||||||||||

getPureObj :: Object -> PureObject | |||||||||||

Takes an object and returns the pure object contained within it. | |||||||||||

Produced by Haddock version 0.6 |