ContentsIndex
Physics
Contents
New data types and type synonyms
Functions
Core functionality
Ray utilities
Vector utilities
Colours
Sample colours
Miscellaneous functions
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
data PureObject
= Sphere Point Double
| Plane Distance Vector
data Object = Object PureObject Double Double Colour
data Light = Light Point Colour
newtype Point = Pt (Double, Double, Double)
newtype Vector = Vec (Double, Double, Double)
newtype Colour = Col (Double, Double, Double)
type Distance = Double
type Time = Double
data Ray = Ray Point Vector
intersect :: Ray -> PureObject -> Maybe (Time, Vector)
intersectPt :: Point -> PureObject -> Bool
vecToLight :: Point -> Light -> Vector
intensity :: Point -> Light -> Colour
rayAt :: Ray -> Time -> Point
rayOrigin :: Ray -> Point
rayDir :: Ray -> Vector
magnitude :: Vector -> Distance
dot :: Vector -> Vector -> Double
vecFrom :: Point -> Point -> Vector
scaleVec :: Double -> Vector -> Vector
unit :: Vector -> Vector
angleBetween :: Vector -> Vector -> Double
distBetween :: Point -> Point -> Double
rotateInPlane :: Vector -> Vector -> Double -> Vector
cross :: Vector -> Vector -> Vector
scaleCol :: Double -> Colour -> Colour
red :: Colour
green :: Colour
blue :: Colour
black :: Colour
white :: Colour
doubleRes :: Double
(==*) :: Double -> Double -> Bool
getPureObj :: Object -> PureObject
New data types and type synonyms
data PureObject
Describes only an object's shape, size and position.
Constructors
Sphere Point Double
Plane Distance Vector
Instances
Show PureObject
Eq PureObject
data Object
An object with properties: diffuse reflection coefficient specular reflection coefficient, and Colour
Constructors
Object PureObject Double Double Colour
Instances
Show Object
Eq Object
data Light
Constructors
Light Point Colour
Instances
Show Light
Eq Light
newtype Point
Points
Constructors
Pt (Double, Double, Double)
Instances
Show Point
Eq Point
newtype Vector
Vectors
Constructors
Vec (Double, Double, Double)
Instances
Num Vector
Show Vector
Eq Vector
newtype Colour
Colours. Components should be in range [0.0, 1.0]
Constructors
Col (Double, Double, Double)
Instances
Num Colour
Show Colour
Eq Colour
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
Ray Point Vector
Instances
Show Ray
Eq 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
:: Vectorunit normal vector
-> Vectorvector
-> Doubletheta
-> 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