Copyright | (C) Frank Staals |
---|---|
License | see the LICENSE file |
Maintainer | Frank Staals |
Safe Haskell | None |
Language | Haskell2010 |
\(d\)-dimensional lines.
Synopsis
- data Line d r = Line {
- _anchorPoint :: !(Point d r)
- _direction :: !(Vector d r)
- direction :: forall d r. Lens' (Line d r) (Vector d r)
- anchorPoint :: forall d r. Lens' (Line d r) (Point d r)
- lineThrough :: (Num r, Arity d) => Point d r -> Point d r -> Line d r
- verticalLine :: Num r => r -> Line 2 r
- horizontalLine :: Num r => r -> Line 2 r
- perpendicularTo :: Num r => Line 2 r -> Line 2 r
- isPerpendicularTo :: (Num r, Eq r) => Vector 2 r -> Line 2 r -> Bool
- isIdenticalTo :: (Eq r, Arity d) => Line d r -> Line d r -> Bool
- isParallelTo :: (Eq r, Fractional r, Arity d) => Line d r -> Line d r -> Bool
- onLine :: (Eq r, Fractional r, Arity d) => Point d r -> Line d r -> Bool
- onLine2 :: (Ord r, Num r) => Point 2 r -> Line 2 r -> Bool
- pointAt :: (Num r, Arity d) => r -> Line d r -> Point d r
- toOffset :: (Eq r, Fractional r, Arity d) => Point d r -> Line d r -> Maybe r
- toOffset' :: (Eq r, Fractional r, Arity d) => Point d r -> Line d r -> r
- sqDistanceTo :: (Fractional r, Arity d) => Point d r -> Line d r -> r
- sqDistanceToArg :: (Fractional r, Arity d) => Point d r -> Line d r -> (r, Point d r)
- class HasSupportingLine t where
- supportingLine :: t -> Line (Dimension t) (NumType t)
- fromLinearFunction :: Num r => r -> r -> Line 2 r
- toLinearFunction :: forall r. (Fractional r, Eq r) => Line 2 r -> Maybe (r, r)
- data SideTest
- onSide :: (Ord r, Num r) => Point 2 r -> Line 2 r -> SideTest
- liesAbove :: (Ord r, Num r) => Point 2 r -> Line 2 r -> Bool
- bisector :: Fractional r => Point 2 r -> Point 2 r -> Line 2 r
- cmpSlope :: (Num r, Ord r) => Line 2 r -> Line 2 r -> Ordering
d-dimensional Lines
A line is given by an anchor point and a vector indicating the direction.
Line | |
|
Instances
Arity d => Functor (Line d) Source # | |
Arity d => Foldable (Line d) Source # | |
Defined in Data.Geometry.Line.Internal fold :: Monoid m => Line d m -> m # foldMap :: Monoid m => (a -> m) -> Line d a -> m # foldr :: (a -> b -> b) -> b -> Line d a -> b # foldr' :: (a -> b -> b) -> b -> Line d a -> b # foldl :: (b -> a -> b) -> b -> Line d a -> b # foldl' :: (b -> a -> b) -> b -> Line d a -> b # foldr1 :: (a -> a -> a) -> Line d a -> a # foldl1 :: (a -> a -> a) -> Line d a -> a # elem :: Eq a => a -> Line d a -> Bool # maximum :: Ord a => Line d a -> a # minimum :: Ord a => Line d a -> a # | |
Arity d => Traversable (Line d) Source # | |
(Arity d, Eq r, Fractional r) => Eq (Line d r) Source # | |
(Show r, Arity d) => Show (Line d r) Source # | |
Generic (Line d r) Source # | |
(NFData r, Arity d) => NFData (Line d r) Source # | |
Defined in Data.Geometry.Line.Internal | |
(Arbitrary r, Arity d, Num r, Eq r) => Arbitrary (Line d r) Source # | |
(Fractional r, Arity d, Arity (d + 1)) => IsTransformable (Line d r) Source # | Lines are transformable, via line segments |
Defined in Data.Geometry.Line transformBy :: Transformation (Dimension (Line d r)) (NumType (Line d r)) -> Line d r -> Line d r Source # | |
HasSupportingLine (Line d r) Source # | |
Defined in Data.Geometry.Line.Internal | |
(Ord r, Fractional r) => IsIntersectableWith (Line 2 r) (Boundary (Rectangle p r)) | |
Defined in Data.Geometry.Line | |
(Eq r, Fractional r) => IsIntersectableWith (Line 3 r) (Plane r) | |
(Eq r, Fractional r, Arity d) => IsIntersectableWith (Point d r) (Line d r) | |
(Ord r, Num r) => IsIntersectableWith (Point 2 r) (Line 2 r) | |
(Eq r, Fractional r) => IsIntersectableWith (Line 2 r) (Line 2 r) Source # | |
(Ord r, Fractional r) => IsIntersectableWith (Line 2 r) (Rectangle p r) | |
(Fractional r, Ord r) => IsIntersectableWith (Line 2 r) (HalfSpace 2 r) | |
(Ord r, Floating r) => IsIntersectableWith (Line 2 r) (Circle p r) | |
(Fractional r, Ord r, HasBoundingLines o) => IsIntersectableWith (Line 2 r) (Slab o a r) | |
(Fractional r, Ord r) => IsIntersectableWith (Line 2 r) (Triangle 2 p r) | |
(Fractional r, Ord r) => IsIntersectableWith (Line 3 r) (Triangle 3 p r) | |
(Ord r, Fractional r) => IsIntersectableWith (LineSegment 2 p r) (Line 2 r) | |
Defined in Data.Geometry.LineSegment intersect :: LineSegment 2 p r -> Line 2 r -> Intersection (LineSegment 2 p r) (Line 2 r) intersects :: LineSegment 2 p r -> Line 2 r -> Bool nonEmptyIntersection :: proxy (LineSegment 2 p r) -> proxy (Line 2 r) -> Intersection (LineSegment 2 p r) (Line 2 r) -> Bool | |
type Rep (Line d r) Source # | |
Defined in Data.Geometry.Line.Internal type Rep (Line d r) = D1 (MetaData "Line" "Data.Geometry.Line.Internal" "hgeometry-0.9.0.0-inplace" False) (C1 (MetaCons "Line" PrefixI True) (S1 (MetaSel (Just "_anchorPoint") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (Point d r)) :*: S1 (MetaSel (Just "_direction") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (Vector d r)))) | |
type NumType (Line d r) Source # | |
Defined in Data.Geometry.Line.Internal | |
type Dimension (Line d r) Source # | |
Defined in Data.Geometry.Line.Internal | |
type IntersectionOf (Line 2 r) (Boundary (Rectangle p r)) | |
Defined in Data.Geometry.Line | |
type IntersectionOf (Line 2 r) (Boundary (Polygon t p r)) | |
Defined in Data.Geometry.Polygon | |
type IntersectionOf (Line 3 r) (Plane r) | |
type IntersectionOf (Point d r) (Line d r) | |
Defined in Data.Geometry.Line | |
type IntersectionOf (Line d r) (HalfSpace d r) | |
type IntersectionOf (Line 2 r) (Line 2 r) Source # | The intersection of two lines is either: NoIntersection, a point or a line. |
type IntersectionOf (Line 2 r) (Rectangle p r) | |
Defined in Data.Geometry.Line type IntersectionOf (Line 2 r) (Rectangle p r) = NoIntersection ': (Point 2 r ': (LineSegment 2 () r ': ([] :: [Type]))) | |
type IntersectionOf (Line 2 r) (Circle p r) | No intersection, one touching point, or two points |
type IntersectionOf (HalfLine 2 r) (Line 2 r) | |
type IntersectionOf (Line 2 r) (Slab o a r) | |
Defined in Data.Geometry.Slab type IntersectionOf (Line 2 r) (Slab o a r) = NoIntersection ': (Line 2 r ': (LineSegment 2 a r ': ([] :: [Type]))) | |
type IntersectionOf (Line 2 r) (Triangle 2 p r) | |
Defined in Data.Geometry.Triangle type IntersectionOf (Line 2 r) (Triangle 2 p r) = NoIntersection ': (Point 2 r ': (LineSegment 2 () r ': ([] :: [Type]))) | |
type IntersectionOf (Line 3 r) (Triangle 3 p r) | |
Defined in Data.Geometry.Triangle type IntersectionOf (Line 3 r) (Triangle 3 p r) = NoIntersection ': (Point 3 r ': (LineSegment 3 () r ': ([] :: [Type]))) | |
type IntersectionOf (LineSegment 2 p r) (Line 2 r) | |
Defined in Data.Geometry.LineSegment type IntersectionOf (LineSegment 2 p r) (Line 2 r) = NoIntersection ': (Point 2 r ': (LineSegment 2 p r ': ([] :: [Type]))) |
anchorPoint :: forall d r. Lens' (Line d r) (Point d r) Source #
Functions on lines
lineThrough :: (Num r, Arity d) => Point d r -> Point d r -> Line d r Source #
A line may be constructed from two points.
verticalLine :: Num r => r -> Line 2 r Source #
horizontalLine :: Num r => r -> Line 2 r Source #
perpendicularTo :: Num r => Line 2 r -> Line 2 r Source #
Given a line l with anchor point p and vector v, get the line perpendicular to l that also goes through p. The resulting line m is oriented such that v points into the left halfplane of m.
>>>
perpendicularTo $ Line (Point2 3 4) (Vector2 (-1) 2)
Line (Point2 [3,4]) (Vector2 [-2,-1])
isPerpendicularTo :: (Num r, Eq r) => Vector 2 r -> Line 2 r -> Bool Source #
Test if a vector is perpendicular to the line.
isIdenticalTo :: (Eq r, Arity d) => Line d r -> Line d r -> Bool Source #
Test if two lines are identical, meaning; if they have exactly the same anchor point and directional vector.
isParallelTo :: (Eq r, Fractional r, Arity d) => Line d r -> Line d r -> Bool Source #
Test if the two lines are parallel.
>>>
lineThrough origin (point2 1 0) `isParallelTo` lineThrough (point2 1 1) (point2 2 1)
True>>>
lineThrough origin (point2 1 0) `isParallelTo` lineThrough (point2 1 1) (point2 2 2)
False
onLine :: (Eq r, Fractional r, Arity d) => Point d r -> Line d r -> Bool Source #
Test if point p lies on line l
>>>
origin `onLine` lineThrough origin (point2 1 0)
True>>>
point2 10 10 `onLine` lineThrough origin (point2 2 2)
True>>>
point2 10 5 `onLine` lineThrough origin (point2 2 2)
False
onLine2 :: (Ord r, Num r) => Point 2 r -> Line 2 r -> Bool Source #
Specific 2d version of testing if apoint lies on a line.
pointAt :: (Num r, Arity d) => r -> Line d r -> Point d r Source #
Get the point at the given position along line, where 0 corresponds to the anchorPoint of the line, and 1 to the point anchorPoint .+^ directionVector
toOffset :: (Eq r, Fractional r, Arity d) => Point d r -> Line d r -> Maybe r Source #
Given point p and a line (Line q v), Get the scalar lambda s.t. p = q + lambda v. If p does not lie on the line this returns a Nothing.
toOffset' :: (Eq r, Fractional r, Arity d) => Point d r -> Line d r -> r Source #
Given point p *on* a line (Line q v), Get the scalar lambda s.t.
p = q + lambda v. (So this is an unsafe version of toOffset
)
pre: the input point p lies on the line l.
sqDistanceTo :: (Fractional r, Arity d) => Point d r -> Line d r -> r Source #
Squared distance from point p to line l
sqDistanceToArg :: (Fractional r, Arity d) => Point d r -> Line d r -> (r, Point d r) Source #
The squared distance between the point p and the line l, and the point m realizing this distance.
Supporting Lines
class HasSupportingLine t where Source #
Types for which we can compute a supporting line, i.e. a line that contains the thing of type t.
Instances
HasSupportingLine (Line d r) Source # | |
Defined in Data.Geometry.Line.Internal | |
HasSupportingLine (HalfLine d r) Source # | |
Defined in Data.Geometry.HalfLine | |
(Num r, Arity d) => HasSupportingLine (LineSegment d p r) Source # | |
Defined in Data.Geometry.LineSegment supportingLine :: LineSegment d p r -> Line (Dimension (LineSegment d p r)) (NumType (LineSegment d p r)) Source # |
Convenience functions on Two dimensional lines
fromLinearFunction :: Num r => r -> r -> Line 2 r Source #
Create a line from the linear function ax + b
toLinearFunction :: forall r. (Fractional r, Eq r) => Line 2 r -> Maybe (r, r) Source #
get values a,b s.t. the input line is described by y = ax + b. returns Nothing if the line is vertical
Result of a side test
onSide :: (Ord r, Num r) => Point 2 r -> Line 2 r -> SideTest Source #
Given a point q and a line l, compute to which side of l q lies. For vertical lines the left side of the line is interpeted as below.
>>>
point2 10 10 `onSide` (lineThrough origin $ point2 10 5)
Above>>>
point2 10 10 `onSide` (lineThrough origin $ point2 (-10) 5)
Above>>>
point2 5 5 `onSide` (verticalLine 10)
Below>>>
point2 5 5 `onSide` (lineThrough origin $ point2 (-3) (-3))
On
liesAbove :: (Ord r, Num r) => Point 2 r -> Line 2 r -> Bool Source #
Test if the query point q lies (strictly) above line l
bisector :: Fractional r => Point 2 r -> Point 2 r -> Line 2 r Source #
Get the bisector between two points
cmpSlope :: (Num r, Ord r) => Line 2 r -> Line 2 r -> Ordering Source #
Compares the lines on slope. Vertical lines are considered larger than anything else.
>>>
(Line origin (Vector2 5 1)) `cmpSlope` (Line origin (Vector2 3 3))
LT>>>
(Line origin (Vector2 5 1)) `cmpSlope` (Line origin (Vector2 (-3) 3))
GT>>>
(Line origin (Vector2 5 1)) `cmpSlope` (Line origin (Vector2 0 1))
LT