SGplus-1.1: (updated) Small geometry library for dealing with vectors and collision detection

Safe HaskellSafe
LanguageHaskell98

Data.SG.Geometry

Description

This module has the type-class (and associated functions) for dealing with geometric systems of 2 or 3 dimensions.

Synopsis

Documentation

class (VectorNum rel, Coord rel, Coord pt, IsomorphicVectors rel pt, IsomorphicVectors pt rel) => Geometry rel pt ln | rel -> pt ln, pt -> rel ln, ln -> rel pt where Source #

A geometry system, parameterised over points, relative (free) vectors, and lines. There are separate instances for two dimensions and for three dimensions. Each pair of type-class parameters is uniquely determined by the other parameter (i.e. by the dimensionality, and which vector type you are using).

Minimal implementation: everything but scaleRel.

Minimal complete definition

plusDir, fromPt, getLineVecs, makeLine

Methods

scaleRel :: Num a => a -> rel a -> rel a Source #

Scales a relative (free) vector by the given amount.

plusDir :: (Num a, Eq a, Show a) => pt a -> rel a -> pt a Source #

Adds a relative (free) vector to a given point.

fromPt :: (Num a, Eq a, Show a) => pt a -> pt a -> rel a Source #

Determines the relative (free) vector to the first parameter from the second parameter. So:

Point2 (1,8) `fromPt` Point2 (3,4) == Point2 (-2,3)

getLineVecs :: Num a => ln a -> (pt a, rel a) Source #

Given a line, converts it back into its point and relative vector. It should always be the case that uncurry makeLine . getLineVecs is the identity function.

makeLine :: Num a => pt a -> rel a -> ln a Source #

Given a point and relative vector, creates a line. It should always be the case that uncurry makeLine . getLineVecs is the identity function.

Instances

Geometry Triple Triple LineTriple Source # 

Methods

scaleRel :: Num a => a -> Triple a -> Triple a Source #

plusDir :: (Num a, Eq a, Show a) => Triple a -> Triple a -> Triple a Source #

fromPt :: (Num a, Eq a, Show a) => Triple a -> Triple a -> Triple a Source #

getLineVecs :: Num a => LineTriple a -> (Triple a, Triple a) Source #

makeLine :: Num a => Triple a -> Triple a -> LineTriple a Source #

Geometry Pair Pair LinePair Source # 

Methods

scaleRel :: Num a => a -> Pair a -> Pair a Source #

plusDir :: (Num a, Eq a, Show a) => Pair a -> Pair a -> Pair a Source #

fromPt :: (Num a, Eq a, Show a) => Pair a -> Pair a -> Pair a Source #

getLineVecs :: Num a => LinePair a -> (Pair a, Pair a) Source #

makeLine :: Num a => Pair a -> Pair a -> LinePair a Source #

Geometry Rel2' Point2' Line2' Source # 

Methods

scaleRel :: Num a => a -> Rel2' a -> Rel2' a Source #

plusDir :: (Num a, Eq a, Show a) => Point2' a -> Rel2' a -> Point2' a Source #

fromPt :: (Num a, Eq a, Show a) => Point2' a -> Point2' a -> Rel2' a Source #

getLineVecs :: Num a => Line2' a -> (Point2' a, Rel2' a) Source #

makeLine :: Num a => Point2' a -> Rel2' a -> Line2' a Source #

Geometry Rel3' Point3' Line3' Source # 

Methods

scaleRel :: Num a => a -> Rel3' a -> Rel3' a Source #

plusDir :: (Num a, Eq a, Show a) => Point3' a -> Rel3' a -> Point3' a Source #

fromPt :: (Num a, Eq a, Show a) => Point3' a -> Point3' a -> Rel3' a Source #

getLineVecs :: Num a => Line3' a -> (Point3' a, Rel3' a) Source #

makeLine :: Num a => Point3' a -> Rel3' a -> Line3' a Source #

minusDir :: (Num a, Geometry rel pt ln, Eq a, Show a) => pt a -> rel a -> pt a Source #

Adds the negation of the relative (free) vector to the point.

toPt :: (Geometry rel pt ln, Num a, Eq a, Show a) => pt a -> pt a -> rel a Source #

The flipped version of fromPt.

lineTo :: (Num a, Geometry rel pt ln, Eq a, Show a) => pt a -> pt a -> ln a Source #

Gets the line from the first point, to the second point.

lineFrom :: (Num a, Geometry rel pt ln, Eq a, Show a) => pt a -> pt a -> ln a Source #

The flipped version of lineTo.

getLineStart :: (Num a, Geometry rel pt ln) => ln a -> pt a Source #

Gets the point at the start of the line.

getLineDir :: (Num a, Geometry rel pt ln) => ln a -> rel a Source #

Gets the direction vector of the line.

getLineEnd :: (Geometry rel pt ln, Num a, Eq a, Show a) => ln a -> pt a Source #

Gets the point at the end of the line.

makeLength :: (Floating a, Ord a, Geometry rel pt ln) => a -> ln a -> ln a Source #

Alters the line to the given length, but with the same start point and direction.

alongLine :: (Num a, Geometry rel pt ln, Eq a, Show a) => a -> ln a -> pt a Source #

Given a multiple of the direction vector (this is not distance unless the direction vector is a unit vector), calculates that point.

distAlongLine :: (Geometry rel pt ln, Ord a, Floating a, Show a) => pt a -> ln a -> Maybe a Source #

Checks if the given point is on the given line (to within a small epsilon-tolerance). If it is, gives back the distance along the line (as a multiple of its direction vector) to the point in a Just wrapper. If the point is not on the line, Nothing is returned.

isOnLine :: (Geometry rel pt ln, Ord a, Floating a, Show a) => pt a -> ln a -> Bool Source #

Checks if the given point is on the given line (to within a small epsilon-tolerance).

nearestDistOnLine :: (Geometry rel pt ln, Ord a, Floating a, Eq a, Show a) => pt a -> ln a -> a Source #

Finds the nearest point on the line to the given point, and gives back its distance along the line (as a multiple of the direction vector). Since the nearest distance will be at a right-angle to the point, this is the same as projecting the point onto the line.

nearestPointOnLine :: (Geometry rel pt ln, Ord a, Floating a, Show a) => pt a -> ln a -> pt a Source #

Finds the nearest point on the line to the given point, and gives back the point.

valueAtX :: (Geometry rel pt ln, Coord2 rel, Coord2 pt, Fractional a, Eq a) => ln a -> a -> Maybe a Source #

Gives the distance along the line (2D or 3D) at a given X value. Returns Nothing if the line is parallel to the YZ plane (in 2D, if the X component of the line is zero). The value returned is a multiple of the direction vector of the line, which will only be the same as distance if the direction vector is a unit vector.

valueAtY :: (Geometry rel pt ln, Coord2 rel, Coord2 pt, Fractional a, Eq a) => ln a -> a -> Maybe a Source #

Gives the distance along the line (2D or 3D) at a given Y value. Returns Nothing if the line is parallel to the XZ plane (in 2D, if the Y component of the line is zero). The value returned is a multiple of the direction vector of the line, which will only be the same as distance if the direction vector is a unit vector.

valueAtZ :: (Geometry rel pt ln, Coord3 rel, Coord3 pt, Fractional a, Eq a) => ln a -> a -> Maybe a Source #

Gives the distance along the 3D line at a given Z value. Returns Nothing if the line is parallel to the XY plane. The value returned is a multiple of the direction vector of the line, which will only be the same as distance if the direction vector is a unit vector.

pointAtX :: (Geometry rel pt ln, Coord2 rel, Coord2 pt, Fractional a, Eq a, Show a) => ln a -> a -> Maybe (pt a) Source #

pointAtX (and the Y and Z equivalents) are wrappers around valueAtX (and similar) that give back the point rather than distance along the line.

pointAtY :: (Geometry rel pt ln, Coord2 rel, Coord2 pt, Fractional a, Eq a, Show a) => ln a -> a -> Maybe (pt a) Source #

pointAtX (and the Y and Z equivalents) are wrappers around valueAtX (and similar) that give back the point rather than distance along the line.

pointAtZ :: (Geometry rel pt ln, Coord3 rel, Coord3 pt, Fractional a, Eq a, Show a) => ln a -> a -> Maybe (pt a) Source #