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

HGeometry.HyperPlane.Class

Description

Classes for representing hyperplanes in d-dimensional space.

Synopsis

Documentation

class (NumType hyperPlane ~ r, Dimension hyperPlane ~ d, Has_ Vector_ d r, Has_ Vector_ (1 + d) r) => HyperPlane_ hyperPlane (d :: Natural) r | hyperPlane -> d, hyperPlane -> r where Source #

A class to represent hyperplanes in d-dimensional space.

Minimal complete definition

Nothing

Methods

evalHyperPlaneEquation :: (Num r, Point_ point d r) => hyperPlane -> point -> r Source #

Evalute the expression \(a_0 + \sum_i=1^d a_i*p_i \) at the given point.

>>> evalHyperPlaneEquation myLine (Point2 5 10)
-3.0

default evalHyperPlaneEquation :: (Num r, Point_ point d r, Has_ Metric_ (d + 1) r) => hyperPlane -> point -> r Source #

hyperPlaneEquation :: hyperPlane -> Vector (d + 1) r Source #

A hyperplane \(h) has coefficients \(a_i \in \mathbb{R}\) so that a point \( (p_1,..,p_d) \) lies on (h) iff: \( a_0 + \sum_i=1^d a_i*p_i = 0 \)

this fuction returns the vector of these coefficients \(\langle a_0,..,a_d \rangle\).

>>> hyperPlaneEquation myLine
Vector3 2.0 1.0 (-1.0)
>>> hyperPlaneEquation myLineAgain
Vector3 2.0 1.0 (-1.0)
>>> hyperPlaneEquation myLineAsNV
Vector3 2.0 1.0 (-1.0)

so for example myLineAsNV actually a line with slope 1 through the point (0,2)

default hyperPlaneEquation :: (NonVerticalHyperPlane_ hyperPlane d r, Num r, 1 <= d, Has_ Vector_ (d + 1) r, KnownNat (d - 1)) => hyperPlane -> Vector (d + 1) r Source #

normalVector :: hyperPlane -> Vector d r Source #

Get the normal vector of the hyperplane. The vector points into the positive halfspace.

>>> normalVector myVerticalLine
Vector2 1.0 (-0.0)
>>> normalVector myLine
Vector2 (-1.0) 1.0

default normalVector :: (KnownNat d, Num r, Eq r, 1 <= d, Has_ Vector_ (d + 1) r, d <= (d + 1)) => hyperPlane -> Vector d r Source #

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

Test if a point lies on a hyperplane.

>>> Point2 0 2 `onHyperPlane` myLineAgain
True
>>> Point2 1 3 `onHyperPlane` myLineAgain
True
>>> Point2 1 5 `onHyperPlane` myLineAgain
False
>>> Point2 0 2 `onHyperPlane` myLineAsNV
True
>>> Point2 1 3 `onHyperPlane` myLineAsNV
True
>>> Point2 1 5 `onHyperPlane` myLineAsNV
False

default onHyperPlane :: (Point_ point d r, Eq r, Num r) => point -> hyperPlane -> Bool Source #

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

Test if a point lies on a hyperplane. Returns the sign when evaluating the hyperplane equation.

>>> Point2 0 2 `onSideTest` myLineAgain
EQ
>>> Point2 1 3 `onSideTest` myLineAgain
EQ
>>> Point2 1 5 `onSideTest` myLineAgain
GT
>>> Point2 4 5 `onSideTest` myLineAgain
LT
>>> Point2 0 0 `onSideTest` HyperPlane2 1 (-1) 0
LT
>>> Point2 1 1 `onSideTest` myVerticalLine
LT
>>> Point2 10 1 `onSideTest` myVerticalLine
GT
>>> Point2 5 20 `onSideTest` myVerticalLine
EQ
>>> Point2 0 1 `onSideTest` myOtherLine
LT
>>> Point2 0 (-2) `onSideTest` myOtherLine
EQ
>>> Point2 1 (-3.5) `onSideTest` myOtherLine
EQ
>>> Point2 1 (-4) `onSideTest` myOtherLine
GT

Instances

Instances details
HyperPlane_ (VerticalOrLineEQ r) 2 r Source # 
Instance details

Defined in HGeometry.Line.General

Methods

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

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

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

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

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

MkHyperPlaneConstraints 2 r => HyperPlane_ (LineEQ r) 2 r Source # 
Instance details

Defined in HGeometry.Line.LineEQ

Methods

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

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

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

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

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

HyperPlane_ hyperPlane d r => HyperPlane_ (hyperPlane :+ extra) d r Source # 
Instance details

Defined in HGeometry.HyperPlane.Class

Methods

evalHyperPlaneEquation :: (Num r, Point_ point d r) => (hyperPlane :+ extra) -> point -> r Source #

hyperPlaneEquation :: (hyperPlane :+ extra) -> Vector (d + 1) r Source #

normalVector :: (hyperPlane :+ extra) -> Vector d r Source #

onHyperPlane :: (Point_ point d r, Eq r, Num r) => point -> (hyperPlane :+ extra) -> Bool Source #

onSideTest :: (Point_ point d r, Ord r, Num r) => point -> (hyperPlane :+ extra) -> Ordering Source #

MkHyperPlaneConstraints d r => HyperPlane_ (HyperPlane d r) d r Source # 
Instance details

Defined in HGeometry.HyperPlane.Internal

Methods

evalHyperPlaneEquation :: (Num r, Point_ point d r) => HyperPlane d r -> point -> r Source #

hyperPlaneEquation :: HyperPlane d r -> Vector (d + 1) r Source #

normalVector :: HyperPlane d r -> Vector d r Source #

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

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

(MkHyperPlaneConstraints d r, Has_ Additive_ (d - 1) r, 2 <= d, (d - 1) <= d, 1 <= d, (1 + (d - 1)) ~ d, ((d - 1) + 1) ~ d) => HyperPlane_ (NonVerticalHyperPlane d r) d r Source # 
Instance details

Defined in HGeometry.HyperPlane.NonVertical

Methods

evalHyperPlaneEquation :: (Num r, Point_ point d r) => NonVerticalHyperPlane d r -> point -> r Source #

hyperPlaneEquation :: NonVerticalHyperPlane d r -> Vector (d + 1) r Source #

normalVector :: NonVerticalHyperPlane d r -> Vector d r Source #

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

onSideTest :: (Point_ point d r, Ord r, Num r) => point -> NonVerticalHyperPlane d r -> Ordering 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 #

class HyperPlane_ hyperPlane d r => ConstructableHyperPlane_ hyperPlane (d :: Natural) r where Source #

Class representing hyperplanes with methods to construct the hyperplane.

Minimal complete definition

hyperPlaneFromEquation

Associated Types

type HyperPlaneFromEquationConstraint hyperPlane (d :: Natural) r Source #

Additional constraints for constructing a hyperplane from its equation.

type HyperPlaneFromEquationConstraint hyperPlane (d :: Natural) r = ()

Methods

hyperPlaneFromEquation :: Vector (d + 1) r -> hyperPlane Source #

Given the coefficients \(a_0,..,a_d\) of the equation, i.e. so that

\( a_0 + \sum_i=1^d a_i*p_i = 0 \)

construct the hyperplane form it.

>>> hyperPlaneFromEquation (Vector3 10 2 1) :: HyperPlane 2 Int -- the line 2*x + 1*y + 10 = 0
HyperPlane [10,2,1]
>>> hyperPlaneFromEquation $ Vector4 100 5 3 (-1)  :: HyperPlane 3 Int -- the plane 5*x + 3*y + (-1)*z + 100= 0
HyperPlane [100,5,3,-1]
>>> myOtherLine == hyperPlaneFromEquation (Vector3 4 3 2)
True

fromPointAndNormal :: (Point_ point d r, Num r) => point -> Vector d r -> hyperPlane Source #

Construct a Hyperplane from a point and a normal. The normal points into the halfplane for which the side-test is positive.

>>> myVerticalLine == fromPointAndNormal (Point2 5 30) (Vector2 1 0)
True

default fromPointAndNormal :: (Point_ point d r, Num r, ConstructableHyperPlane_ hyperPlane d r, HyperPlaneFromEquationConstraint hyperPlane d r, Has_ Metric_ d r, Has_ Vector_ (d + 1) r) => point -> Vector d r -> hyperPlane Source #

Instances

Instances details
(Fractional r, Eq r) => ConstructableHyperPlane_ (VerticalOrLineEQ r) 2 r Source # 
Instance details

Defined in HGeometry.Line.General

Associated Types

type HyperPlaneFromEquationConstraint (VerticalOrLineEQ r) 2 r 
Instance details

Defined in HGeometry.Line.General

Methods

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

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

(MkHyperPlaneConstraints 2 r, Fractional r, Eq r) => ConstructableHyperPlane_ (LineEQ r) 2 r Source # 
Instance details

Defined in HGeometry.Line.LineEQ

Associated Types

type HyperPlaneFromEquationConstraint (LineEQ r) 2 r 
Instance details

Defined in HGeometry.Line.LineEQ

Methods

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

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

(ConstructableHyperPlane_ hyperPlane d r, Default extra) => ConstructableHyperPlane_ (hyperPlane :+ extra) d r Source # 
Instance details

Defined in HGeometry.HyperPlane.Class

Associated Types

type HyperPlaneFromEquationConstraint (hyperPlane :+ extra) d r 
Instance details

Defined in HGeometry.HyperPlane.Class

type HyperPlaneFromEquationConstraint (hyperPlane :+ extra) d r = HyperPlaneFromEquationConstraint hyperPlane d r

Methods

hyperPlaneFromEquation :: Vector (d + 1) r -> hyperPlane :+ extra Source #

fromPointAndNormal :: (Point_ point d r, Num r) => point -> Vector d r -> hyperPlane :+ extra Source #

MkHyperPlaneConstraints d r => ConstructableHyperPlane_ (HyperPlane d r) d r Source # 
Instance details

Defined in HGeometry.HyperPlane.Internal

Associated Types

type HyperPlaneFromEquationConstraint (HyperPlane d r) d r 
Instance details

Defined in HGeometry.HyperPlane.Internal

Methods

hyperPlaneFromEquation :: Vector (d + 1) r -> HyperPlane d r Source #

fromPointAndNormal :: (Point_ point d r, Num r) => point -> Vector d r -> HyperPlane d r Source #

(MkHyperPlaneConstraints d r, Has_ Additive_ (d - 1) r, Fractional r, Eq r, 2 <= d, (d - 1) <= d, 1 <= d, (1 + (d - 1)) ~ d, 0 <= ((d + 1) - 1), KnownNat (d - 1), ((d - 1) + 1) ~ d) => ConstructableHyperPlane_ (NonVerticalHyperPlane d r) d r Source # 
Instance details

Defined in HGeometry.HyperPlane.NonVertical

(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 #

class HyperPlane_ hyperPlane d r => NonVerticalHyperPlane_ hyperPlane (d :: Natural) r where Source #

Non-vertical hyperplanes.

Minimal complete definition

hyperPlaneCoefficients

Methods

evalAt :: (Num r, 1 <= d, Point_ point (d - 1) r) => point -> hyperPlane -> r Source #

Get the coordinate in dimension \(d\) of the hyperplane at the given position.

>>> evalAt (Point1 1) myLineAsNV
3.0
>>> evalAt (Point1 10) myLineAsNV
12.0
>>> evalAt (Point1 5) <$> asNonVerticalHyperPlane myOtherLine
Just (-9.5)

default evalAt :: (Num r, 1 <= d, Point_ point (d - 1) r, Has_ Metric_ d r, (d - 1) <= d, KnownNat (d - 1), ((d - 1) + 1) ~ d) => point -> hyperPlane -> r Source #

hyperPlaneCoefficients :: Lens' hyperPlane (Vector d r) Source #

The coefficients \( \langle a_1,..,a_d \rangle \) such that a point \(p = (p_1,..,p_d) \) lies on the hyperplane the given coefficients iff

\( a_d + \sum_i=1^{d-1} a_i*p_i = p_d \)

>>> view hyperPlaneCoefficients myLineAsNV
Vector2 1.0 2.0
>>> view hyperPlaneCoefficients myLine
Vector2 1.0 2.0
>>> view hyperPlaneCoefficients $ Plane 1 2 3
Vector3 1 2 3
>>> asNonVerticalHyperPlane myOtherLine ^?_Just.hyperPlaneCoefficients
Just (Vector2 (-1.5) (-2.0))

verticalSideTest :: (1 <= d, Point_ point d r, Ord r, Num r) => point -> hyperPlane -> Ordering Source #

Test if a point q lies above a non-vertical hyperplane h (i.e. verticalSideTest q h == GT), on the hyperplane (== EQ), or below (LT).

>>> Point2 0 2 `verticalSideTest` myLineAsNV
EQ
>>> Point2 1 3 `verticalSideTest` myLineAsNV
EQ
>>> Point2 1 5 `verticalSideTest` myLineAsNV
GT
>>> Point2 4 5 `verticalSideTest` myLineAsNV
LT
>>> Point2 0 1 `verticalSideTest` myOtherNVLine
GT
>>> Point2 0 (-2) `verticalSideTest` myOtherNVLine
EQ
>>> Point2 1 (-3.5) `verticalSideTest` myOtherNVLine
EQ
>>> Point2 1 (-4) `verticalSideTest` myOtherNVLine
LT

default verticalSideTest :: (Point_ point d r, Num r, Ord r, 1 <= d, ((d - 1) + 1) ~ d, (d - 1) <= d, KnownNat (d - 1), Has_ Metric_ d r, Has_ Additive_ (d - 1) r) => point -> hyperPlane -> Ordering Source #

Instances

Instances details
(MkHyperPlaneConstraints 2 r, Num r) => NonVerticalHyperPlane_ (LineEQ r) 2 r Source # 
Instance details

Defined in HGeometry.Line.LineEQ

Methods

evalAt :: (Num r, 1 <= 2, Point_ point (2 - 1) r) => point -> LineEQ r -> r Source #

hyperPlaneCoefficients :: Lens' (LineEQ r) (Vector 2 r) Source #

verticalSideTest :: (1 <= 2, Point_ point 2 r, Ord r, Num r) => point -> LineEQ r -> Ordering Source #

NonVerticalHyperPlane_ hyperPlane d r => NonVerticalHyperPlane_ (hyperPlane :+ extra) d r Source # 
Instance details

Defined in HGeometry.HyperPlane.Class

Methods

evalAt :: (Num r, 1 <= d, Point_ point (d - 1) r) => point -> (hyperPlane :+ extra) -> r Source #

hyperPlaneCoefficients :: Lens' (hyperPlane :+ extra) (Vector d r) Source #

verticalSideTest :: (1 <= d, Point_ point d r, Ord r, Num r) => point -> (hyperPlane :+ extra) -> Ordering Source #

(MkHyperPlaneConstraints d r, (1 + (d - 1)) ~ d, Has_ Additive_ (d - 1) r, Num r, 2 <= d, (d - 1) <= d, 1 <= d, (1 + (d - 1)) ~ d, ((d - 1) + 1) ~ d) => NonVerticalHyperPlane_ (NonVerticalHyperPlane d r) d r Source # 
Instance details

Defined in HGeometry.HyperPlane.NonVertical

Methods

evalAt :: (Num r, 1 <= d, Point_ point (d - 1) r) => point -> NonVerticalHyperPlane d r -> r Source #

hyperPlaneCoefficients :: Lens' (NonVerticalHyperPlane d r) (Vector d r) Source #

verticalSideTest :: (1 <= d, Point_ point d r, Ord r, Num r) => point -> NonVerticalHyperPlane d r -> Ordering Source #

type Plane_ plane = NonVerticalHyperPlane_ plane 3 Source #

Shorthand for Non-vertical hyperplanes in R^3

pattern Plane_ :: Plane_ plane r => r -> r -> r -> plane Source #

Destructs a Plane in R^3 into the equation z = ax + by + c

isParallelTo :: forall hyperPlane (d :: Natural) r hyperPlane'. (HyperPlane_ hyperPlane d r, HyperPlane_ hyperPlane' d r, Has_ Metric_ d r, Num r, Eq r, 1 <= d) => hyperPlane -> hyperPlane' -> Bool Source #

Test if two hyperplanes are parallel.

pointOn :: forall hyperPlane (d :: Natural) r. (HyperPlane_ hyperPlane d r, Eq r, Fractional r, Has_ Additive_ d r, FoldableWithIndex Int (Vector d), Has_ Vector_ (d + 1) r, d <= (d + 1), 0 <= ((d + 1) - 1)) => hyperPlane -> Point d r Source #

Produce a point that lies on the hyperplane. No gurantees are given about which point

>>> pointOn myLine
Point2 (-2.0) 0.0

class HyperPlaneFromPoints hyperPlane where Source #

Class that tells us we can construct a hyperplane from a vector of points.

Methods

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

Construct a hyperplane through the given d points.

Instances

Instances details
Eq r => HyperPlaneFromPoints (HyperPlane 2 r) Source # 
Instance details

Defined in HGeometry.HyperPlane.Internal

Methods

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

Num r => HyperPlaneFromPoints (HyperPlane 3 r) Source # 
Instance details

Defined in HGeometry.HyperPlane.Internal

Methods

hyperPlaneThrough :: forall point (d :: Nat) r0. (Point_ point d r0, HyperPlane_ (HyperPlane 3 r) d r0, Num r0) => Vector d point -> HyperPlane 3 r 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 #

showPlaneEquation :: (Plane_ plane r, Show r) => plane -> String Source #

Renders the defining equation of a plane in R^3 in some human readable format.

>>> showPlaneEquation (Plane 5 3 2)
"z = 5x + 3y + 2"