Safe Haskell | Safe |
---|---|
Language | Haskell98 |
This module has the type-class (and associated functions) for dealing with geometric systems of 2 or 3 dimensions.
- 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
- minusDir :: (Num a, Geometry rel pt ln, Eq a, Show a) => pt a -> rel a -> pt a
- toPt :: (Geometry rel pt ln, Num a, Eq a, Show a) => pt a -> pt a -> rel a
- lineTo :: (Num a, Geometry rel pt ln, Eq a, Show a) => pt a -> pt a -> ln a
- lineFrom :: (Num a, Geometry rel pt ln, Eq a, Show a) => pt a -> pt a -> ln a
- getLineStart :: (Num a, Geometry rel pt ln) => ln a -> pt a
- getLineDir :: (Num a, Geometry rel pt ln) => ln a -> rel a
- getLineEnd :: (Geometry rel pt ln, Num a, Eq a, Show a) => ln a -> pt a
- makeLength :: (Floating a, Ord a, Geometry rel pt ln) => a -> ln a -> ln a
- alongLine :: (Num a, Geometry rel pt ln, Eq a, Show a) => a -> ln a -> pt a
- distAlongLine :: (Geometry rel pt ln, Ord a, Floating a, Show a) => pt a -> ln a -> Maybe a
- isOnLine :: (Geometry rel pt ln, Ord a, Floating a, Show a) => pt a -> ln a -> Bool
- nearestDistOnLine :: (Geometry rel pt ln, Ord a, Floating a, Eq a, Show a) => pt a -> ln a -> a
- nearestPointOnLine :: (Geometry rel pt ln, Ord a, Floating a, Show a) => pt a -> ln a -> pt a
- valueAtX :: (Geometry rel pt ln, Coord2 rel, Coord2 pt, Fractional a, Eq a) => ln a -> a -> Maybe a
- valueAtY :: (Geometry rel pt ln, Coord2 rel, Coord2 pt, Fractional a, Eq a) => ln a -> a -> Maybe a
- valueAtZ :: (Geometry rel pt ln, Coord3 rel, Coord3 pt, Fractional a, Eq a) => ln a -> a -> Maybe a
- pointAtX :: (Geometry rel pt ln, Coord2 rel, Coord2 pt, Fractional a, Eq a, Show a) => ln a -> a -> Maybe (pt a)
- pointAtY :: (Geometry rel pt ln, Coord2 rel, Coord2 pt, Fractional a, Eq a, Show a) => ln a -> a -> Maybe (pt a)
- pointAtZ :: (Geometry rel pt ln, Coord3 rel, Coord3 pt, Fractional a, Eq a, Show a) => ln a -> a -> Maybe (pt a)
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.
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.
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.