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

HGeometry.Transformation

Description

 
Synopsis

Documentation

newtype Transformation (d :: Natural) r Source #

A type representing a Transformation for d dimensional objects

Constructors

Transformation (Matrix (d + 1) (d + 1) r) 

Instances

Instances details
(Num r, OptMatrix_ (d + 1) r) => Monoid (Transformation d r) Source # 
Instance details

Defined in HGeometry.Transformation.Internal

(Num r, OptMatrix_ (d + 1) r) => Semigroup (Transformation d r) Source # 
Instance details

Defined in HGeometry.Transformation.Internal

Show (Matrix (d + 1) (d + 1) r) => Show (Transformation d r) Source # 
Instance details

Defined in HGeometry.Transformation.Internal

Eq (Matrix (d + 1) (d + 1) r) => Eq (Transformation d r) Source # 
Instance details

Defined in HGeometry.Transformation.Internal

Ord (Matrix (d + 1) (d + 1) r) => Ord (Transformation d r) Source # 
Instance details

Defined in HGeometry.Transformation.Internal

type NumType (Transformation d r) Source # 
Instance details

Defined in HGeometry.Transformation.Internal

type NumType (Transformation d r) = r

transformationMatrix :: forall (d :: Natural) r s p f. (Profunctor p, Functor f) => p (Matrix (d + 1) (d + 1) r) (f (Matrix (d + 1) (d + 1) s)) -> p (Transformation d r) (f (Transformation d s)) Source #

Transformations and Matrices are isomorphic.

(|.|) :: forall r (d :: Natural). (Num r, OptMatrix_ (d + 1) r) => Transformation d r -> Transformation d r -> Transformation d r Source #

Compose transformations (right to left)

identity :: forall r (d :: Natural). (Num r, OptMatrix_ (d + 1) r) => Transformation d r Source #

Identity transformation; i.e. the transformation which does not change anything.

inverseOf :: forall r (d :: Natural). (Fractional r, OptMatrix_ (d + 1) r, Invertible (d + 1)) => Transformation d r -> Transformation d r Source #

Compute the inverse transformation

>>> inverseOf $ translation (Vector2 (10.0) (5.0))
Transformation {_transformationMatrix = Matrix (Vector3 (Vector3 1.0 0.0 (-10.0)) (Vector3 0.0 1.0 (-5.0)) (Vector3 0.0 0.0 1.0))}

class IsTransformable g where Source #

A class representing types that can be transformed using a transformation

Minimal complete definition

Nothing

Methods

transformBy :: Transformation (Dimension g) (NumType g) -> g -> g Source #

default transformBy :: forall (d :: Nat) r point. (DefaultTransformByConstraints g d r, Point_ point d r, HasPoints g g point point) => Transformation (Dimension g) (NumType g) -> g -> g Source #

Instances

Instances details
IsTransformable geom => IsTransformable (NonEmpty geom) Source # 
Instance details

Defined in HGeometry.Transformation.Internal

(Point_ point d r, IsTransformable point) => IsTransformable (Box point) Source # 
Instance details

Defined in HGeometry.Box

Methods

transformBy :: Transformation (Dimension (Box point)) (NumType (Box point)) -> Box point -> Box point Source #

Num r => IsTransformable (Ellipse r) Source # 
Instance details

Defined in HGeometry.Ellipse

(DefaultTransformByConstraints (Triangle point) d r, Point_ point d r) => IsTransformable (Triangle point) Source # 
Instance details

Defined in HGeometry.Triangle

Methods

transformBy :: Transformation (Dimension (Triangle point)) (NumType (Triangle point)) -> Triangle point -> Triangle point Source #

IsTransformable geom => IsTransformable [geom] Source # 
Instance details

Defined in HGeometry.Transformation.Internal

Methods

transformBy :: Transformation (Dimension [geom]) (NumType [geom]) -> [geom] -> [geom] Source #

IsTransformable core => IsTransformable (core :+ extra) Source # 
Instance details

Defined in HGeometry.Transformation.Internal

Methods

transformBy :: Transformation (Dimension (core :+ extra)) (NumType (core :+ extra)) -> (core :+ extra) -> core :+ extra Source #

(Point_ point d r, IxValue (endPoint point) ~ point, EndPoint_ (endPoint point), IsTransformable point) => IsTransformable (LineSegment endPoint point) Source # 
Instance details

Defined in HGeometry.LineSegment.Internal

Methods

transformBy :: Transformation (Dimension (LineSegment endPoint point)) (NumType (LineSegment endPoint point)) -> LineSegment endPoint point -> LineSegment endPoint point Source #

(Fractional r, Has_ Vector_ d r, OptMatrix_ (d + 1) r, HasComponents (Vector (d + 1) (Vector (d + 1) r)) (Vector (d + 1) r), d <= ((d + 1) - 1), d <= (d + 1)) => IsTransformable (Point d r) Source # 
Instance details

Defined in HGeometry.Transformation.Internal

Methods

transformBy :: Transformation (Dimension (Point d r)) (NumType (Point d r)) -> Point d r -> Point d r Source #

(Fractional r, Has_ Vector_ d r, OptMatrix_ (d + 1) r, HasComponents (Vector (d + 1) (Vector (d + 1) r)) (Vector (d + 1) r), d <= ((d + 1) - 1), d <= (d + 1)) => IsTransformable (Vector d r) Source # 
Instance details

Defined in HGeometry.Transformation.Internal

Methods

transformBy :: Transformation (Dimension (Vector d r)) (NumType (Vector d r)) -> Vector d r -> Vector d r Source #

type TransformationConstraints (d :: Nat) r = (KnownNat d, Has_ Vector_ d r, OptMatrix_ (d + 1) r, HasComponents (Vector (d + 1) r) (Vector (d + 1) (Vector (d + 1) r)), Has_ Additive_ (d + 1) r) Source #

Some constraints that we will pretty much need to transform a d dimensional object whose numtype is r

type DefaultTransformByConstraints g (d :: Nat) r = (d ~ Dimension g, r ~ NumType g, OptMatrix_ (d + 1) r, Fractional r, Has_ Additive_ d r, HasComponents (Vector (d + 1) (Vector (d + 1) r)) (Vector (d + 1) r), d <= (d + 1), d <= ((d + 1) - 1)) Source #

Bunch of constraints we need for the default implementation of transformBy

type OptMatrix_ (d :: Nat) r = (Has_ Additive_ d r, Has_ Vector_ d (Vector d r), Ixed (Vector d r), Ixed (Vector d (Vector d r))) Source #

shorthand for square matrixecs

translation :: forall (d :: Nat) r vector. (Num r, Vector_ vector d r, TransformationConstraints d r, d <= ((d + 1) - 1)) => vector -> Transformation d r Source #

Create translation transformation from a vector.

>>> transformBy (translation $ Vector2 1 2) $ Point2 2 3
Point2 3.0 5.0

scaling :: forall (d :: Nat) r vector. (Num r, Vector_ vector d r, TransformationConstraints d r) => vector -> Transformation d r Source #

Create scaling transformation from a vector.

>>> transformBy (scaling $ Vector2 2 (-1)) $ Point2 2 3
Point2 4.0 (-3.0)

uniformScaling :: forall (d :: Nat) r. (Num r, TransformationConstraints d r) => r -> Transformation d r Source #

Create scaling transformation from a scalar that is applied to all dimensions.

>>> transformBy (uniformScaling 5) $ Point2 2 3
Point2 10.0 15.0
>>> uniformScaling 5 == scaling (Vector2 5 5)
True
>>> uniformScaling 5 == scaling (Vector3 5 5 5)
True

translateBy :: forall g vector (d :: Nat). (IsTransformable g, Num (NumType g), Vector_ vector d (NumType g), TransformationConstraints d (NumType g), Dimension g ~ d, d <= ((d + 1) - 1)) => vector -> g -> g Source #

Translate a given point.

>>> translateBy (Vector2 1 2) $ Point2 2 3
Point2 3.0 5.0

scaleBy :: forall g vector (d :: Nat). (IsTransformable g, Num (NumType g), Vector_ vector d (NumType g), TransformationConstraints d (NumType g), Dimension g ~ d, d <= ((d + 1) - 1)) => vector -> g -> g Source #

Scale a given point.

>>> scaleBy (Vector2 2 (-1)) $ Point2 2 3
Point2 4.0 (-3.0)

scaleUniformlyBy :: forall g (d :: Nat). (IsTransformable g, Num (NumType g), TransformationConstraints d (NumType g), Dimension g ~ d, d <= ((d + 1) - 1)) => NumType g -> g -> g Source #

Scale a given point uniformly in all dimensions.

>>> scaleUniformlyBy 5 $ Point2 2 3
Point2 10.0 15.0

rotateTo :: Num r => Vector 3 (Vector 3 r) -> Transformation 3 r Source #

Given three new unit-length basis vectors (u,v,w) that map to (x,y,z), construct the appropriate rotation that does this.

rotateXYZ :: Floating r => Vector 3 r -> Transformation 3 r Source #

Euler angle rotation; in order XYZ (from bottom to top in the gimbal hierarchy)

the angles CCW and given in radians.

rotateX :: Floating r => r -> Transformation 3 r Source #

Rotate $alpha$-radians CCW around the x-axis

rotateY :: Floating r => r -> Transformation 3 r Source #

Rotate $beta$-radians CCW around the y-axis

rotateZ :: Floating r => r -> Transformation 3 r Source #

Rotate $gamma$-radians CCW around the z-axis

skewX :: Num r => r -> Transformation 2 r Source #

Skew transformation that keeps the y-coordinates fixed and shifts the x coordinates.

rotation :: Floating r => r -> Transformation 2 r Source #

Create a matrix that corresponds to a rotation by a radians counter-clockwise around the origin.

reflection :: Floating r => r -> Transformation 2 r Source #

Create a matrix that corresponds to a reflection in a line through the origin which makes an angle of a radians with the positive x-asis, in counter-clockwise orientation.

reflectionV :: Num r => Transformation 2 r Source #

Vertical reflection

reflectionH :: Num r => Transformation 2 r Source #

Horizontal reflection

fitToBox :: forall box (d :: Nat) g point r. (NumType g ~ r, Dimension g ~ d, IsTransformable g, IsBoxable g, Box_ box point, Point_ point d r, Ord r, Fractional r, TransformationConstraints d r, Functor (Vector d), Zip (Vector d), d <= ((d + 1) - 1)) => box -> g -> g Source #

Given a box r and a geometry g with its boundingbox, transform the g to fit r.

fitToBoxTransform :: forall box (d :: Nat) g point r. (NumType g ~ r, Dimension g ~ d, IsTransformable g, IsBoxable g, Box_ box point, Point_ point d r, Ord r, Fractional r, TransformationConstraints d r, Functor (Vector d), Zip (Vector d), d <= ((d + 1) - 1)) => box -> g -> Transformation d r Source #

Given a box r and a geometry g with its boundingbox, compute a transformation can fit g to r.