|
|
|
|
|
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 |
Describes only an object's shape, size and position. | Constructors | | Instances | |
|
|
data Object |
An object with properties: diffuse reflection coefficient
specular reflection coefficient, and Colour | Constructors | | Instances | |
|
|
data Light |
|
|
newtype Point |
Points | Constructors | Pt (Double, Double, Double) | |
| Instances | |
|
|
newtype Vector |
Vectors | Constructors | Vec (Double, Double, Double) | |
| Instances | |
|
|
newtype Colour |
Colours. Components should be in range [0.0, 1.0] | Constructors | Col (Double, Double, Double) | |
| Instances | |
|
|
type Distance = Double |
|
type Time = Double |
|
data Ray |
Rays have an origin (a Point) and a direction (a Vector). The direction
should be a unit vector. | Constructors | | Instances | |
|
|
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 |
:: Vector | unit normal vector | -> Vector | vector | -> Double | theta | -> Vector | | Rotates a vector by theta radians in the plane defined
by the normal vector that is the first argument.
The rotation is clockwise when one views the plane with the
unit normal vector pointing towards oneself. Equivalently, the rotation
is anti-clockwise when viewing the plane with the normal vector
pointing away from oneself. Negative arguments mean an
anti-clockwise rotation. This function preserves the magnitude
of the vector. If the original vector was a unit vector, so is
the result.
Precondition:
1. Expects that the normal vector is a unit normal vector
2. The vector to be rotated must be in the plane. i.e.
It must be perpendicular to the unit normal vector |
|
|
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 |