Safe Haskell  Safe 

Language  Haskell98 
A module with types to use in a 2D system, and various helper functions. Several more functions are available for use in the Data.SG.Geometry module.
 newtype Point2' a = Point2 (a, a)
 data Rel2' a = Rel2 (a, a) a
 makeRel2 :: Num a => (a, a) > Rel2' a
 data Line2' a = Line2 {
 getLineStart2 :: Point2' a
 getLineDir2 :: Rel2' a
 toAngle :: RealFloat a => Rel2' a > a
 perpendicular2 :: Num a => Rel2' a > Rel2' a
 reflectAgainst2 :: (Floating a, Ord a, Eq a, Show a) => Rel2' a > Rel2' a > Rel2' a
 reflectAgainstIfNeeded2 :: (Floating a, Ord a, Eq a, Show a) => Rel2' a > Rel2' a > Rel2' a
 intersectLines2 :: (Fractional a, Eq a, Show a) => Line2' a > Line2' a > Maybe (a, a)
 findAllIntersections2 :: (Fractional a, Eq a, Show a) => ([Line2' a], [Line2' a]) > [((Line2' a, a), (Line2' a, a))]
 intersectLineCircle :: (Ord a, Floating a) => Line2' a > (Point2' a, a) > Maybe (a, a)
 point2AtZ :: (Geometry rel pt ln, Coord3 rel, Coord3 pt, Fractional a, Eq a, Show a) => ln a > a > Maybe (Point2' a)
Documentation
A point in 2D space.
Point2 (a, a) 
Functor Point2' Source #  
Applicative Point2' Source #  
Foldable Point2' Source #  
Traversable Point2' Source #  
VectorNum Point2' Source #  
Coord2 Point2' Source #  
Coord Point2' Source #  
IsomorphicVectors Pair Point2' Source #  
IsomorphicVectors Rel2' Point2' Source #  
IsomorphicVectors Point2' Pair Source #  
IsomorphicVectors Point2' Rel2' Source #  
Geometry Rel2' Point2' Line2' Source #  
Eq a => Eq (Point2' a) Source #  
Ord a => Ord (Point2' a) Source #  
Read a => Read (Point2' a) Source #  
Show a => Show (Point2' a) Source #  
A relative vector (free vector) in 2D space. The pair are the x and y components,
and the last item is the squared magnitude of the vector, which is stored
with it to speed up various operations. It is suggested you use makeRel2
to create one of these, unless the square magnitude is easily apparent, e.g. Rel2
(0, 2) 4
Rel2 (a, a) a 
Foldable Rel2' Source #  
VectorNum Rel2' Source #  
Coord2 Rel2' Source #  
Coord Rel2' Source #  
IsomorphicVectors Pair Rel2' Source #  
IsomorphicVectors Rel2' Pair Source #  
IsomorphicVectors Rel2' Point2' Source #  
IsomorphicVectors Point2' Rel2' Source #  
Geometry Rel2' Point2' Line2' Source #  
Eq a => Eq (Rel2' a) Source #  
(Show a, Eq a, Num a) => Num (Rel2' a) Source #  Multiplication doesn't make much sense, but the rest do! 
Ord a => Ord (Rel2' a) Source #  
Read a => Read (Rel2' a) Source #  
Show a => Show (Rel2' a) Source #  
A line in 2D space. A line is a point, and a free vector indicating direction. A line may be treated by a function as either finite (taking the magnitude of the free vector as the length) or infinite (ignoring the magnitude of the direction vector).
Line2  

toAngle :: RealFloat a => Rel2' a > a Source #
Gets the angle, in radians, anticlockwise from the xaxis. If you pass the allzero vector, the return value will be zero.
perpendicular2 :: Num a => Rel2' a > Rel2' a Source #
Gets the vector perpendicular to the given 2D vector. If you pass it a vector that is in a clockwise direction around a polygon, the result will always face away from the polygon.
reflectAgainst2 :: (Floating a, Ord a, Eq a, Show a) => Rel2' a > Rel2' a > Rel2' a Source #
Reflects the first direction vector against the given surface normal. The resulting direction vector should have the same magnitude as the original first parameter. An example:
makeRel2 (3, 4) `reflectAgainst2` makeRel2 (0,1) == makeRel2 (3, 4)
reflectAgainstIfNeeded2 :: (Floating a, Ord a, Eq a, Show a) => Rel2' a > Rel2' a > Rel2' a Source #
Reflects the first direction vector against the given surface normal. The resulting direction vector should have the same magnitude as the original first parameter.
The reflection is not performed if the given vector points along the same direction as the normal, that is: if once projected onto the normal vector, the component is positive, the original first parameter is returned unmodified. Examples:
makeRel2 (3, 4) `reflectAgainstIfNeeded2` makeRel2 (0,1) == makeRel2 (3, 4) makeRel2 (3, 4) `reflectAgainstIfNeeded2` makeRel2 (0,1) == makeRel2 (3, 4)
intersectLines2 :: (Fractional a, Eq a, Show a) => Line2' a > Line2' a > Maybe (a, a) Source #
Given two 2D lines, finds out their intersection. The first part of the
result pair is how much to multiply the direction vector of the first line
by (and add it to the start point of the first line) to reach the
intersection, and the second part is the corresponding item for the second line.
So given Just (a, b) = intersectLines2 la lb
, it should be the case (minus
some possible precision loss) that alongLine a la == alongLine b lb
. If the
lines are parallel, Nothing is returned.
Note that this function assumes the lines are infinite. If you want to check for the intersection of two finite lines, check if the two parts of the result pair are both in the range 0 to 1 inclusive.
findAllIntersections2 :: (Fractional a, Eq a, Show a) => ([Line2' a], [Line2' a]) > [((Line2' a, a), (Line2' a, a))] Source #
Finds all the intersections between a line from the first list and a line from the second list, and how far along that is each line. That is, this is a bit like mapMaybe composed with intersectLines2 on all pairings of a line from the first list and a line from the second list.
intersectLineCircle :: (Ord a, Floating a) => Line2' a > (Point2' a, a) > Maybe (a, a) Source #
Given a line, and a circle (defined by a point and a radius), finds the points of intersection.
If the line does not intersect the circle, Nothing is returned. If they do
intersect, two values are returned that are distances along the line. That
is, given Just (a, b) = intersectLineCircle l c
, the two points of intersection
are (alongLine l a, alongLine l b)
.
The ordering of the two items in the pair is arbitrary, and if the line is a tangent to the circle, the values will be the same.