| Copyright | (C) Frank Staals |
|---|---|
| License | see the LICENSE file |
| Maintainer | Frank Staals |
| Safe Haskell | None |
| Language | GHC2024 |
HGeometry.HyperPlane.Class
Description
Classes for representing hyperplanes in d-dimensional space.
Synopsis
- 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
- evalHyperPlaneEquation :: (Num r, Point_ point d r) => hyperPlane -> point -> r
- hyperPlaneEquation :: hyperPlane -> Vector (d + 1) r
- normalVector :: hyperPlane -> Vector d r
- onHyperPlane :: (Point_ point d r, Eq r, Num r) => point -> hyperPlane -> Bool
- onSideTest :: (Point_ point d r, Ord r, Num r) => point -> hyperPlane -> Ordering
- class HyperPlane_ hyperPlane d r => ConstructableHyperPlane_ hyperPlane (d :: Natural) r where
- type HyperPlaneFromEquationConstraint hyperPlane (d :: Natural) r
- hyperPlaneFromEquation :: Vector (d + 1) r -> hyperPlane
- fromPointAndNormal :: (Point_ point d r, Num r) => point -> Vector d r -> hyperPlane
- class HyperPlane_ hyperPlane d r => NonVerticalHyperPlane_ hyperPlane (d :: Natural) r where
- type Plane_ plane = NonVerticalHyperPlane_ plane 3
- pattern Plane_ :: Plane_ plane r => r -> r -> r -> plane
- 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
- 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
- class HyperPlaneFromPoints hyperPlane where
- hyperPlaneThrough :: forall point (d :: Nat) r. (Point_ point d r, HyperPlane_ hyperPlane d r, Num r) => Vector d point -> hyperPlane
- showPlaneEquation :: (Plane_ plane r, Show r) => plane -> String
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 myLineVector3 2.0 1.0 (-1.0)>>>hyperPlaneEquation myLineAgainVector3 2.0 1.0 (-1.0)>>>hyperPlaneEquation myLineAsNVVector3 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 myVerticalLineVector2 1.0 (-0.0)>>>normalVector myLineVector2 (-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` myLineAgainTrue>>>Point2 1 3 `onHyperPlane` myLineAgainTrue>>>Point2 1 5 `onHyperPlane` myLineAgainFalse
>>>Point2 0 2 `onHyperPlane` myLineAsNVTrue>>>Point2 1 3 `onHyperPlane` myLineAsNVTrue>>>Point2 1 5 `onHyperPlane` myLineAsNVFalse
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` myLineAgainEQ>>>Point2 1 3 `onSideTest` myLineAgainEQ>>>Point2 1 5 `onSideTest` myLineAgainGT>>>Point2 4 5 `onSideTest` myLineAgainLT>>>Point2 0 0 `onSideTest` HyperPlane2 1 (-1) 0LT
>>>Point2 1 1 `onSideTest` myVerticalLineLT>>>Point2 10 1 `onSideTest` myVerticalLineGT>>>Point2 5 20 `onSideTest` myVerticalLineEQ
>>>Point2 0 1 `onSideTest` myOtherLineLT>>>Point2 0 (-2) `onSideTest` myOtherLineEQ>>>Point2 1 (-3.5) `onSideTest` myOtherLineEQ>>>Point2 1 (-4) `onSideTest` myOtherLineGT
Instances
class HyperPlane_ hyperPlane d r => ConstructableHyperPlane_ hyperPlane (d :: Natural) r where Source #
Class representing hyperplanes with methods to construct the hyperplane.
Minimal complete definition
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 = 0HyperPlane [10,2,1]>>>hyperPlaneFromEquation $ Vector4 100 5 3 (-1) :: HyperPlane 3 Int -- the plane 5*x + 3*y + (-1)*z + 100= 0HyperPlane [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
class HyperPlane_ hyperPlane d r => NonVerticalHyperPlane_ hyperPlane (d :: Natural) r where Source #
Non-vertical hyperplanes.
Minimal complete definition
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) myLineAsNV3.0>>>evalAt (Point1 10) myLineAsNV12.0>>>evalAt (Point1 5) <$> asNonVerticalHyperPlane myOtherLineJust (-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 myLineAsNVVector2 1.0 2.0>>>view hyperPlaneCoefficients myLineVector2 1.0 2.0>>>view hyperPlaneCoefficients $ Plane 1 2 3Vector3 1 2 3>>>asNonVerticalHyperPlane myOtherLine ^?_Just.hyperPlaneCoefficientsJust (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` myLineAsNVEQ>>>Point2 1 3 `verticalSideTest` myLineAsNVEQ>>>Point2 1 5 `verticalSideTest` myLineAsNVGT>>>Point2 4 5 `verticalSideTest` myLineAsNVLT
>>>Point2 0 1 `verticalSideTest` myOtherNVLineGT>>>Point2 0 (-2) `verticalSideTest` myOtherNVLineEQ>>>Point2 1 (-3.5) `verticalSideTest` myOtherNVLineEQ>>>Point2 1 (-4) `verticalSideTest` myOtherNVLineLT
Instances
| (MkHyperPlaneConstraints 2 r, Num r) => NonVerticalHyperPlane_ (LineEQ r) 2 r Source # | |
| NonVerticalHyperPlane_ hyperPlane d r => NonVerticalHyperPlane_ (hyperPlane :+ extra) d r Source # | |
Defined in HGeometry.HyperPlane.Class | |
| (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 # | |
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 myLinePoint2 (-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
| Eq r => HyperPlaneFromPoints (HyperPlane 2 r) Source # | |
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 # | |
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 # | |
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 # | |