wumpus-basic-0.16.0: Basic objects and system code built on Wumpus-Core.

Portability GHC highly unstable Stephen Tetley

Wumpus.Basic.Geometry.Base

Description

Base geometric types and operations.

Synopsis

# 2x2 Matrix

data Matrix2'2 u Source

2x2 matrix, considered to be in row-major form.

``` (M2'2 a b
c d)
```

Constructors

 M2'2 !u !u !u !u

Instances

 Functor Matrix2'2 Eq u => Eq (Matrix2'2 u) Num u => Num (Matrix2'2 u) Show u => Show (Matrix2'2 u)

Construct the identity 2x2 matrix:

``` (M2'2 1 0
0 1 )
```

det2'2 :: Num u => Matrix2'2 u -> uSource

Determinant of a 2x2 matrix.

Transpose a 2x2 matrix.

# Line in equational form

data LineEquation u Source

Line in equational form, i.e. `Ax + By + C = 0`.

Constructors

 LineEquation Fieldsline_eqn_A :: !u line_eqn_B :: !u line_eqn_C :: !u

Instances

 Eq u => Eq (LineEquation u) Show u => Show (LineEquation u)

lineEquation :: Num u => Point2 u -> Point2 u -> LineEquation uSource

`lineEquation` : ` point1 * point2 -> LineEquation `

Construct a line in equational form bisecting the supplied points.

pointViaX :: Fractional u => u -> LineEquation u -> Point2 uSource

`pointViaX` : ` x * line_equation -> Point `

Calculate the point on the line for the supplied `x` value.

pointViaY :: Fractional u => u -> LineEquation u -> Point2 uSource

`pointViaY` : ` y * line_equation -> Point `

Calculate the point on the line for the supplied `y` value.

pointLineDistance :: Floating u => Point2 u -> LineEquation u -> uSource

`pointLineDistance` : ` point -> line -> Distance `

Find the distance from a point to a line in equational form using this formula:

``` P(u,v)
L: Ax + By + C = 0

(A*u) + (B*v) + C
-----------------
sqrt \$ (A^2) +(B^2)
```

A positive distance indicates the point is above the line, negative indicates below.

# Line segment

data LineSegment u Source

Constructors

 LineSegment (Point2 u) (Point2 u)

Instances

 Eq u => Eq (LineSegment u) Ord u => Ord (LineSegment u) Show u => Show (LineSegment u)

rectangleLineSegments :: Num u => u -> u -> Point2 u -> [LineSegment u]Source

`rectangleLineSegments` : ` half_width * half_height -> [LineSegment] `

Compute the line segments of a rectangle.

polygonLineSegments :: [Point2 u] -> [LineSegment u]Source

`polygonLineSegments` : ` [point] -> [LineSegment] `

Build the line segments of a polygon fome a list of its vertices.

# Cubic Bezier curves

data BezierCurve u Source

A Strict cubic Bezier curve.

Constructors

 BezierCurve !(Point2 u) !(Point2 u) !(Point2 u) !(Point2 u)

Instances

 Eq u => Eq (BezierCurve u) Ord u => Ord (BezierCurve u) Show u => Show (BezierCurve u)

bezierLength :: (Floating u, Ord u, FromPtSize u) => BezierCurve u -> uSource

`bezierLength` : ``` start_point * control_1 * control_2 * end_point -> Length ```

Find the length of a Bezier curve. The result is an approximation, with the tolerance is 0.1 of a point. This seems good enough for drawing (potentially the tolerance could be larger still).

The result is found through repeated subdivision so the calculation is potentially costly.

subdivide :: Fractional u => BezierCurve u -> (BezierCurve u, BezierCurve u)Source

Curve subdivision via de Casteljau's algorithm.

subdividet :: Real u => u -> BezierCurve u -> (BezierCurve u, BezierCurve u)Source

subdivide with an affine weight along the line...

bezierArcPoints :: Floating u => Radian -> u -> Radian -> Point2 u -> [Point2 u]Source

`bezierArcPoints` : ` apex_angle * radius * rotation * center -> [Point] `

``` ang should be in the range 0 < ang < 360deg.
```
``` if   0 < ang <=  90 returns 4 points
if  90 < ang <= 180 returns 7 points
if 180 < ang <= 270 returns 10 points
if 270 < ang <  360 returns 13 points
```

bezierMinorArc :: Floating u => Radian -> u -> Radian -> Point2 u -> BezierCurve uSource

`bezierMinorArc` : ` apex_angle * radius * rotation * center -> BezierCurve `

``` ang should be in the range 0 < ang <= 90deg.
```

# Functions

affineComb :: Real u => u -> Point2 u -> Point2 u -> Point2 uSource

Affine combination...

midpoint :: Fractional u => Point2 u -> Point2 u -> Point2 uSource

`midpoint` : ` start_point * end_point -> Midpoint `

Mid-point on the line formed between the two supplied points.

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

`lineAngle` : ` start_point * end_point -> Angle `

Calculate the counter-clockwise angle between the line formed by the two points and the horizontal plane.