hgeometry-kernel
Copyright(C) Frank Staals
Licensesee the LICENSE file
MaintainerFrank Staals
Safe HaskellNone
LanguageGHC2024

HGeometry.Line

Description

Lines in d-dimensional space.

Synopsis

Documentation

anchorPoint :: forall (d :: Nat) r f. Functor f => (Point d r -> f (Point d r)) -> LinePV d r -> f (LinePV d r) Source #

Lens to access the anchor point of the line

bisector :: (Fractional r, Point_ point 2 r) => point -> point -> LinePV 2 r Source #

Get the bisector between two points

cmpSlope :: (Num r, Ord r) => LinePV 2 r -> LinePV 2 r -> Ordering Source #

Compares the lines on slope. Vertical lines are considered larger than anything else.

>>> (LinePV origin (Vector2 5 1)) `cmpSlope` (LinePV origin (Vector2 3 3))
LT
>>> (LinePV origin (Vector2 5 1)) `cmpSlope` (LinePV origin (Vector2 (-3) 3))
GT
>>> (LinePV origin (Vector2 5 1)) `cmpSlope` (LinePV origin (Vector2 0 1))
LT

fromLinearFunction :: Num r => r -> r -> LinePV 2 r Source #

Create a line from the linear function ax + b

isIdenticalTo :: forall (d :: Nat) r. Eq (Vector d r) => LinePV d r -> LinePV d r -> Bool Source #

Test if two lines are identical, meaning; if they have exactly the same anchor point and directional vector.

isPerpendicularTo :: (Num r, Eq r) => Vector 2 r -> LinePV 2 r -> Bool Source #

Test if a vector is perpendicular to the line.

leftHalfPlane :: (Num r, Ord r) => LinePV 2 r -> HalfSpaceF (LinePV 2 r) Source #

Given the oriented line, computes the halfspace left of the line.

onSide :: (Ord r, Num r, Point_ point 2 r) => point -> LinePV 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)
LeftSide
>>> Point2 10 10 `onSide` (lineThrough origin $ Point2 (-10) 5)
RightSide
>>> Point2 5 5 `onSide` (verticalLine 10)
LeftSide
>>> Point2 5 5 `onSide` (lineThrough origin $ Point2 (-3) (-3))
OnLine

perpendicularTo :: Num r => LinePV 2 r -> LinePV 2 r Source #

Given a line l with anchor point p and vector v, get the line m perpendicular to l that also goes through p. The line is oriented *into* the right halfplane of l.

>>> perpendicularTo $ LinePV (Point2 3 4) (Vector2 (-1) 2)
LinePV (Point2 3 4) (Vector2 2 1)
>>> perpendicularTo $ LinePV (Point2 (-1000) 268) (Vector2 (-50) 8)
LinePV (Point2 (-1000) 268) (Vector2 8 50)

rightHalfPlane :: (Num r, Ord r) => LinePV 2 r -> HalfSpaceF (LinePV 2 r) Source #

Given the oriented line, computes the halfspace right of the line.

toLinearFunction :: (Fractional r, Ord r) => LinePV 2 r -> Maybe (LineEQ r) Source #

get values a,b s.t. the input line is described by y = ax + b. returns Nothing if the line is vertical

class HasDirection t where Source #

Types that have a Direction field

Methods

direction :: forall (d :: Nat) r. (Dimension t ~ d, NumType t ~ r) => Lens' t (Vector d r) Source #

Lens to access the direction field

Instances

Instances details
HasDirection (HalfLine point) Source # 
Instance details

Defined in HGeometry.HalfLine

Methods

direction :: forall (d :: Nat) r. (Dimension (HalfLine point) ~ d, NumType (HalfLine point) ~ r) => Lens' (HalfLine point) (Vector d r) Source #

HasDirection (LinePV d r) Source # 
Instance details

Defined in HGeometry.Line.PointAndVector

Methods

direction :: forall (d0 :: Nat) r0. (Dimension (LinePV d r) ~ d0, NumType (LinePV d r) ~ r0) => Lens' (LinePV d r) (Vector d0 r0) Source #

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

Instances details
Point_ point d r => HasSupportingLine (HalfLine point) Source # 
Instance details

Defined in HGeometry.HalfLine

Methods

supportingLine :: HalfLine point -> LinePV (Dimension (HalfLine point)) (NumType (HalfLine point)) Source #

HasSupportingLine t => HasSupportingLine (t :+ extra) Source # 
Instance details

Defined in HGeometry.Line.PointAndVector

Methods

supportingLine :: (t :+ extra) -> LinePV (Dimension (t :+ extra)) (NumType (t :+ extra)) Source #

HasSupportingLine (LinePV d r) Source # 
Instance details

Defined in HGeometry.Line.PointAndVector

Methods

supportingLine :: LinePV d r -> LinePV (Dimension (LinePV d r)) (NumType (LinePV d r)) Source #

(Point_ point d r, Has_ Metric_ d r, EndPoint_ (endPoint point), IxValue (endPoint point) ~ point, Num r) => HasSupportingLine (LineSegment endPoint point) Source # 
Instance details

Defined in HGeometry.LineSegment.Internal

Methods

supportingLine :: LineSegment endPoint point -> LinePV (Dimension (LineSegment endPoint point)) (NumType (LineSegment endPoint point)) Source #

data LinePV (d :: Nat) r Source #

A line is given by an anchor point and a vector indicating the direction.

Constructors

LinePV 

Fields

Instances

Instances details
(Eq r, Num r) => HasIntersectionWith (LineEQ r) (LinePV 2 r) Source # 
Instance details

Defined in HGeometry.Line

Methods

intersects :: LineEQ r -> LinePV 2 r -> Bool Source #

(Ord r, Fractional r) => IsIntersectableWith (LineEQ r) (LinePV 2 r) Source # 
Instance details

Defined in HGeometry.Line

Methods

intersect :: LineEQ r -> LinePV 2 r -> Intersection (LineEQ r) (LinePV 2 r) Source #

NFData (Vector d r) => NFData (LinePV d r) Source # 
Instance details

Defined in HGeometry.Line.PointAndVector

Methods

rnf :: LinePV d r -> () Source #

Generic (LinePV d r) Source # 
Instance details

Defined in HGeometry.Line.PointAndVector

Associated Types

type Rep (LinePV d r) 
Instance details

Defined in HGeometry.Line.PointAndVector

type Rep (LinePV d r) = D1 ('MetaData "LinePV" "HGeometry.Line.PointAndVector" "hgeometry-kernel-1.0.0.0-inplace" 'False) (C1 ('MetaCons "LinePV" 'PrefixI 'True) (S1 ('MetaSel ('Just "_anchorPoint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Point d r)) :*: S1 ('MetaSel ('Just "_direction") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Vector d r))))

Methods

from :: LinePV d r -> Rep (LinePV d r) x Source #

to :: Rep (LinePV d r) x -> LinePV d r Source #

(Read r, Has_ Additive_ d r, KnownNat d) => Read (LinePV d r) Source # 
Instance details

Defined in HGeometry.Line.PointAndVector

(Show r, Has_ Additive_ d r) => Show (IntersectionOf (LinePV d r) (Ball point)) Source # 
Instance details

Defined in HGeometry.Ball.CenterAndRadius

Methods

showsPrec :: Int -> IntersectionOf (LinePV d r) (Ball point) -> ShowS Source #

show :: IntersectionOf (LinePV d r) (Ball point) -> String Source #

showList :: [IntersectionOf (LinePV d r) (Ball point)] -> ShowS Source #

(Show r, KnownNat d, Has_ Additive_ d r) => Show (LinePV d r) Source # 
Instance details

Defined in HGeometry.Line.PointAndVector

Methods

showsPrec :: Int -> LinePV d r -> ShowS Source #

show :: LinePV d r -> String Source #

showList :: [LinePV d r] -> ShowS Source #

(Eq r, Eq (Vector d r)) => Eq (IntersectionOf (LinePV d r) (Ball point)) Source # 
Instance details

Defined in HGeometry.Ball.CenterAndRadius

Methods

(==) :: IntersectionOf (LinePV d r) (Ball point) -> IntersectionOf (LinePV d r) (Ball point) -> Bool Source #

(/=) :: IntersectionOf (LinePV d r) (Ball point) -> IntersectionOf (LinePV d r) (Ball point) -> Bool Source #

(Ord r, Num r) => Eq (LinePV 2 r) Source # 
Instance details

Defined in HGeometry.Line.PointAndVector

Methods

(==) :: LinePV 2 r -> LinePV 2 r -> Bool Source #

(/=) :: LinePV 2 r -> LinePV 2 r -> Bool Source #

Num r => HyperPlaneFromPoints (LinePV 2 r) Source # 
Instance details

Defined in HGeometry.Line.PointAndVector

Methods

hyperPlaneThrough :: forall point (d :: Nat) r0. (Point_ point d r0, HyperPlane_ (LinePV 2 r) d r0, Num r0) => Vector d point -> LinePV 2 r Source #

HasDirection (LinePV d r) Source # 
Instance details

Defined in HGeometry.Line.PointAndVector

Methods

direction :: forall (d0 :: Nat) r0. (Dimension (LinePV d r) ~ d0, NumType (LinePV d r) ~ r0) => Lens' (LinePV d r) (Vector d0 r0) Source #

HasSupportingLine (LinePV d r) Source # 
Instance details

Defined in HGeometry.Line.PointAndVector

Methods

supportingLine :: LinePV d r -> LinePV (Dimension (LinePV d r)) (NumType (LinePV d r)) Source #

OnSideUpDownTest (LinePV 2 r) Source # 
Instance details

Defined in HGeometry.Line.PointAndVector

Methods

onSideUpDown :: forall (d :: Nat) r0 point. (d ~ Dimension (LinePV 2 r), r0 ~ NumType (LinePV 2 r), Ord r0, Num r0, Point_ point d r0) => point -> LinePV 2 r -> SideTestUpDown Source #

(Fractional r, Has_ Metric_ d r) => HasSquaredEuclideanDistance (LinePV d r) Source # 
Instance details

Defined in HGeometry.Line.PointAndVector

Methods

squaredEuclideanDistTo :: forall r0 (d0 :: Nat) point. (r0 ~ NumType (LinePV d r), d0 ~ Dimension (LinePV d r), Num r0, Point_ point d0 r0) => point -> LinePV d r -> r0 Source #

pointClosestTo :: forall r0 (d0 :: Nat) point. (r0 ~ NumType (LinePV d r), d0 ~ Dimension (LinePV d r), Num r0, Point_ point d0 r0) => point -> LinePV d r -> Point d0 r0 Source #

pointClosestToWithDistance :: forall r0 (d0 :: Nat) point. (r0 ~ NumType (LinePV d r), d0 ~ Dimension (LinePV d r), Num r0, Point_ point d0 r0) => point -> LinePV d r -> (Point d0 r0, r0) Source #

(Has_ Metric_ d r, Fractional r, Eq (Vector d r)) => HasOnLine (LinePV d r) d Source # 
Instance details

Defined in HGeometry.Line.PointAndVector

Methods

onLine :: (Point_ point d r0, Num r0, Eq r0, r0 ~ NumType (LinePV d r), d ~ Dimension (LinePV d r)) => point -> LinePV d r -> Bool Source #

Ord r => HasOnLine (LinePV 2 r) 2 Source # 
Instance details

Defined in HGeometry.Line.PointAndVector

Methods

onLine :: (Point_ point 2 r0, Num r0, Eq r0, r0 ~ NumType (LinePV 2 r), 2 ~ Dimension (LinePV 2 r)) => point -> LinePV 2 r -> Bool Source #

(Eq r, Num r) => ConstructableHyperPlane_ (LinePV 2 r) 2 r Source # 
Instance details

Defined in HGeometry.Line.PointAndVector

Associated Types

type HyperPlaneFromEquationConstraint (LinePV 2 r) 2 r 
Instance details

Defined in HGeometry.Line.PointAndVector

Methods

hyperPlaneFromEquation :: Vector (2 + 1) r -> LinePV 2 r Source #

fromPointAndNormal :: (Point_ point 2 r, Num r) => point -> Vector 2 r -> LinePV 2 r Source #

(Eq r, Num r) => HyperPlane_ (LinePV 2 r) 2 r Source # 
Instance details

Defined in HGeometry.Line.PointAndVector

Methods

evalHyperPlaneEquation :: (Num r, Point_ point 2 r) => LinePV 2 r -> point -> r Source #

hyperPlaneEquation :: LinePV 2 r -> Vector (2 + 1) r Source #

normalVector :: LinePV 2 r -> Vector 2 r Source #

onHyperPlane :: (Point_ point 2 r, Eq r, Num r) => point -> LinePV 2 r -> Bool Source #

onSideTest :: (Point_ point 2 r, Ord r, Num r) => point -> LinePV 2 r -> Ordering Source #

Has_ Metric_ d r => Line_ (LinePV d r) d r Source # 
Instance details

Defined in HGeometry.Line.PointAndVector

Methods

fromPointAndVec :: (Point_ point d r, Line_ (LinePV d r) d r, Num r) => point -> Vector d r -> LinePV d r Source #

(Point_ point d r, Ord r, Fractional r, Has_ Metric_ d r) => HasIntersectionWith (LinePV d r) (Ball point) Source # 
Instance details

Defined in HGeometry.Ball.CenterAndRadius

Methods

intersects :: LinePV d r -> Ball point -> Bool Source #

(Num r, Ord r, Point_ point 2 r) => HasIntersectionWith (LinePV 2 r) (Rectangle point) Source # 
Instance details

Defined in HGeometry.Box

Methods

intersects :: LinePV 2 r -> Rectangle point -> Bool Source #

(Ord r, Num r, Point_ point 2 r) => HasIntersectionWith (LinePV 2 r) (HalfLine point) Source # 
Instance details

Defined in HGeometry.HalfLine

Methods

intersects :: LinePV 2 r -> HalfLine point -> Bool Source #

(Point_ point 3 r, Fractional r, Ord r) => HasIntersectionWith (LinePV 3 r) (Triangle point) Source # 
Instance details

Defined in HGeometry.Triangle

Methods

intersects :: LinePV 3 r -> Triangle point -> Bool Source #

(Point_ point d r, Ord r, Fractional r, Radical r, Has_ Metric_ d r) => IsIntersectableWith (LinePV d r) (Ball point) Source # 
Instance details

Defined in HGeometry.Ball.CenterAndRadius

Methods

intersect :: LinePV d r -> Ball point -> Intersection (LinePV d r) (Ball point) Source #

(Fractional r, Ord r, Point_ point 2 r) => IsIntersectableWith (LinePV 2 r) (Rectangle point) Source # 
Instance details

Defined in HGeometry.Box

Methods

intersect :: LinePV 2 r -> Rectangle point -> Intersection (LinePV 2 r) (Rectangle point) Source #

(Ord r, Fractional r, Point_ point 2 r) => IsIntersectableWith (LinePV 2 r) (HalfLine point) Source # 
Instance details

Defined in HGeometry.HalfLine

Methods

intersect :: LinePV 2 r -> HalfLine point -> Intersection (LinePV 2 r) (HalfLine point) Source #

(Point_ point 2 r, Fractional r, Ord r) => IsIntersectableWith (LinePV 2 r) (ClosedLineSegment point) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection

(Point_ point 2 r, Fractional r, Ord r) => IsIntersectableWith (LinePV 2 r) (OpenLineSegment point) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection

Methods

intersect :: LinePV 2 r -> OpenLineSegment point -> Intersection (LinePV 2 r) (OpenLineSegment point) Source #

(Point_ point 3 r, Fractional r, Ord r) => IsIntersectableWith (LinePV 3 r) (Triangle point) Source # 
Instance details

Defined in HGeometry.Triangle

Methods

intersect :: LinePV 3 r -> Triangle point -> Intersection (LinePV 3 r) (Triangle point) Source #

(Ord r, Num r) => HasIntersectionWith (LinePV 2 r) (LinePV 2 r) Source # 
Instance details

Defined in HGeometry.Line.PointAndVector

Methods

intersects :: LinePV 2 r -> LinePV 2 r -> Bool Source #

(Point_ point 2 r, Num r, Ord r, IxValue (endPoint point) ~ point, EndPoint_ (endPoint point)) => HasIntersectionWith (LinePV 2 r) (LineSegment endPoint point) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection

Methods

intersects :: LinePV 2 r -> LineSegment endPoint point -> Bool Source #

(Ord r, Fractional r) => IsIntersectableWith (LinePV 2 r) (LinePV 2 r) Source # 
Instance details

Defined in HGeometry.Line.PointAndVector

Methods

intersect :: LinePV 2 r -> LinePV 2 r -> Intersection (LinePV 2 r) (LinePV 2 r) Source #

(Point_ point 2 r, Fractional r, Ord r) => IsIntersectableWith (LinePV 2 r) (LineSegment AnEndPoint point) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection

type Intersection (LineEQ r) (LinePV 2 r) Source # 
Instance details

Defined in HGeometry.Line

type Rep (LinePV d r) Source # 
Instance details

Defined in HGeometry.Line.PointAndVector

type Rep (LinePV d r) = D1 ('MetaData "LinePV" "HGeometry.Line.PointAndVector" "hgeometry-kernel-1.0.0.0-inplace" 'False) (C1 ('MetaCons "LinePV" '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 Dimension (LinePV d r) Source # 
Instance details

Defined in HGeometry.Line.PointAndVector

type Dimension (LinePV d r) = d
type NumType (LinePV d r) Source # 
Instance details

Defined in HGeometry.Line.PointAndVector

type NumType (LinePV d r) = r
type HyperPlaneFromEquationConstraint (LinePV 2 r) 2 r Source # 
Instance details

Defined in HGeometry.Line.PointAndVector

type Intersection (LinePV d r) (Ball point) Source # 
Instance details

Defined in HGeometry.Ball.CenterAndRadius

type Intersection (LinePV d r) (Ball point) = Maybe (IntersectionOf (LinePV d r) (Ball point))
type Intersection (LinePV 2 r) (Rectangle point) Source # 
Instance details

Defined in HGeometry.Box

type Intersection (LinePV 2 r) (HalfLine point) Source # 
Instance details

Defined in HGeometry.HalfLine

type Intersection (LinePV 3 r) (Triangle point') Source #

The extra value is the parameter t so that the intersection point is line^.anchor + t*line^.direction

Instance details

Defined in HGeometry.Triangle

data IntersectionOf (LinePV d r) (Ball point) Source #

The extra value is the parameter t, so that the intersection point is line^.anchroPoint + t*line^.direction

Instance details

Defined in HGeometry.Ball.CenterAndRadius

type Intersection (LinePV 2 r) (LinePV 2 r) Source #

The intersection of two lines is either: NoIntersection, a point or a line.

Instance details

Defined in HGeometry.Line.PointAndVector

type Intersection (LinePV 2 r) (LineSegment AnEndPoint point) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection

type Intersection (LinePV 2 r) (LineSegment (EndPoint t) point) Source # 
Instance details

Defined in HGeometry.LineSegment.Intersection

type Intersection (LinePV 2 r) (LineSegment (EndPoint t) point)

class OnSideUpDownTest t where Source #

Class for types that support testing on which side (above, on, below) a particular point is.

Methods

onSideUpDown :: forall (d :: Nat) r point. (d ~ Dimension t, r ~ NumType t, Ord r, Num r, Point_ point d r) => point -> t -> SideTestUpDown Source #

Given a point q and a hyperplane h, compute to which side of h q lies. For vertical hyperplanes the left side of the hyperplane is interpeted as below.

Instances

Instances details
OnSideUpDownTest (LinePV 2 r) Source # 
Instance details

Defined in HGeometry.Line.PointAndVector

Methods

onSideUpDown :: forall (d :: Nat) r0 point. (d ~ Dimension (LinePV 2 r), r0 ~ NumType (LinePV 2 r), Ord r0, Num r0, Point_ point d r0) => point -> LinePV 2 r -> SideTestUpDown Source #

data LineLineIntersectionG r line Source #

Line x Line intersections are either just points or lines.

Constructors

Line_x_Line_Point (Point 2 r) 
Line_x_Line_Line line 

fromLineEQ :: Num r => LineEQ r -> LinePV 2 r Source #

Convert from a LineEQ to a Point and Line

Orphan instances

Fractional r => HasSquaredEuclideanDistance (LineEQ r) Source # 
Instance details

Methods

squaredEuclideanDistTo :: forall r0 (d :: Nat) point. (r0 ~ NumType (LineEQ r), d ~ Dimension (LineEQ r), Num r0, Point_ point d r0) => point -> LineEQ r -> r0 Source #

pointClosestTo :: forall r0 (d :: Nat) point. (r0 ~ NumType (LineEQ r), d ~ Dimension (LineEQ r), Num r0, Point_ point d r0) => point -> LineEQ r -> Point d r0 Source #

pointClosestToWithDistance :: forall r0 (d :: Nat) point. (r0 ~ NumType (LineEQ r), d ~ Dimension (LineEQ r), Num r0, Point_ point d r0) => point -> LineEQ r -> (Point d r0, r0) Source #

(Eq r, Num r) => HasIntersectionWith (LineEQ r) (LinePV 2 r) Source # 
Instance details

Methods

intersects :: LineEQ r -> LinePV 2 r -> Bool Source #

(Ord r, Fractional r) => IsIntersectableWith (LineEQ r) (LinePV 2 r) Source # 
Instance details

Methods

intersect :: LineEQ r -> LinePV 2 r -> Intersection (LineEQ r) (LinePV 2 r) Source #