wumpus-core-0.12.0: Pure Haskell PostScript and SVG generation.

PortabilityGHC only
Stabilityexperimental
Maintainerstephen.tetley@gmail.com

Wumpus.Core.Geometry

Contents

Description

2D geometry

Synopsis

Type family

type family DUnit a :: *Source

Some unit of dimension usually double.

Data types

data Vec2 a Source

Constructors

V2 !a !a 

Instances

Functor Vec2 
Num a => MatrixMult Matrix3'3 (Vec2 a) 
Eq a => Eq (Vec2 a) 
Show a => Show (Vec2 a) 
Num a => Monoid (Vec2 a) 
Num a => VectorSpace (Vec2 a) 
(Scalar a ~ a, Num a, InnerSpace a) => InnerSpace (Vec2 a) 
Num a => AdditiveGroup (Vec2 a) 
Pretty a => Pretty (Vec2 a) 
Pointwise (Vec2 a) 
Num u => Translate (Vec2 u) 
Num u => Scale (Vec2 u) 
(Floating a, Real a) => RotateAbout (Vec2 a) 
(Floating a, Real a) => Rotate (Vec2 a) 

data Point2 a Source

Constructors

P2 !a !a 

Instances

Functor Point2 
Num a => MatrixMult Matrix3'3 (Point2 a) 
Eq a => Eq (Point2 a) 
Show a => Show (Point2 a) 
Num a => AffineSpace (Point2 a) 
Pretty a => Pretty (Point2 a) 
Ord a => CMinMax (Point2 a) 
Pointwise (Point2 a) 
Num u => Translate (Point2 u)

translate x y.

Num u => Scale (Point2 u) 
(Floating a, Real a) => RotateAbout (Point2 a) 
(Floating a, Real a) => Rotate (Point2 a) 

data Frame2 a Source

A two dimensional frame.

The components are the two basis vectors e0 and e1 and the origin o.

Typically these names for the elements will be used:

 Frame2 (V2 e0x e0y) (V2 e1x e1y) (P2 ox oy)

Constructors

Frame2 (Vec2 a) (Vec2 a) (Point2 a) 

Instances

Eq a => Eq (Frame2 a) 
Show a => Show (Frame2 a) 
(Num a, InnerSpace (Vec2 a)) => Monoid (Frame2 a) 
Pretty a => Pretty (Frame2 a) 
ToCTM (Frame2 a) 

data Matrix3'3 a Source

3x3 matrix, considered to be in row-major form.

 (M3'3 a b c
       d e f
       g h i)

For instance the rotation matrix is represented as

  ( cos(a) -sin(a) 0
    sin(a)  cos(a) 0  
      0         0  1 )

This is congruent with the form presented in Santos - Example 45, page 17 extended to 3x3.

ref. David A. Santos Multivariable and Vector Calculus, July 17, 2008 Version.

The right-most column is considered to represent a coordinate:

  ( 1 0 x
    0 1 y  
    0 0 1 ) 

So a translation matrix representing the displacement in x of 40 and in y of 10 would be:

  ( 1 0 40
    0 1 10  
    0 0 1  ) 

Constructors

M3'3 !a !a !a !a !a !a !a !a !a 

data Radian Source

Radian is represented with a distinct type. Equality and ordering are approximate where the epsilon is 0.0001.

Pointwise type class

class Pointwise sh whereSource

Pointwise is a Functor like type class, except that the container/element relationship is defined by a type family rather than a type parameter. This means that applied function must be type preserving.

Associated Types

type Pt sh :: *Source

Methods

pointwise :: (Pt sh -> Pt sh) -> sh -> shSource

Matrix multiply type class

class MatrixMult mat t whereSource

Associated Types

type MatrixParam t :: *Source

Methods

(*#) :: MatrixParam t ~ a => mat a -> t -> tSource

Instances

Vector operations

hvec :: Num a => a -> Vec2 aSource

Construct a vector with horizontal displacement.

vvec :: Num a => a -> Vec2 aSource

Construct a vector with vertical displacement.

avec :: Floating a => Radian -> a -> Vec2 aSource

Construct a vector from an angle and magnitude.

Point operations

langle :: (Floating u, Real u) => Point2 u -> Point2 u -> RadianSource

Frame operations

ortho :: Num a => Point2 a -> Frame2 aSource

frame2Matrix :: Num a => Frame2 a -> Matrix3'3 aSource

Concatenate the elements of the frame as columns forming a 3x3 matrix. Points and vectors are considered homogeneous coordinates - triples where the least element is either 0 indicating a vector or 1 indicating a point:

 Frame (V2 e0x e0y) (V2 e1x e1y) (P2 ox oy)

becomes

 (M3'3 e0x e1x ox
       e0y e1y oy
        0   0   1  )

matrix2Frame :: Matrix3'3 a -> Frame2 aSource

Interpret the matrix as columns forming a frame.

 (M3'3 e0x e1x ox
       e0y e1y oy
        0   0   1  )

becomes

 Frame (V2 e0x e0y) (V2 e1x e1y) (P2 ox oy)

frameProduct :: (Num a, InnerSpace (Vec2 a)) => Frame2 a -> Frame2 a -> Frame2 aSource

Multiplication of frames to form their product.

standardFrame :: Num a => Frame2 a -> BoolSource

Is the origin at (0,0) and are the basis vectors orthogonal with unit length?

Matrix contruction

identityMatrix :: Num a => Matrix3'3 aSource

Construct the identity matrix:

 (M3'3 1 0 0
       0 1 0
       0 0 1 )

scalingMatrix :: Num a => a -> a -> Matrix3'3 aSource

Construct a scaling matrix:

 (M3'3 sx 0  0
       0  sy 0
       0  0  1 )

matrix operations

Radian operations

d2r :: (Floating a, Real a) => a -> RadianSource

Degrees to radians.

r2d :: (Floating a, Real a) => Radian -> aSource

Radians to degrees.