hgeometry-0.12.0.4: Geometric Algorithms, Data structures, and Data types.

Data.Geometry.Transformation

Description

Synopsis

Documentation

>>> import Data.Geometry.LineSegment
>>> import Data.Ext


Transformations

newtype Transformation d r Source #

A type representing a Transformation for d dimensional objects

Constructors

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

Instances

Instances details
 Arity (d + 1) => Functor (Transformation d) Source # Instance detailsDefined in Data.Geometry.Transformation Methodsfmap :: (a -> b) -> Transformation d a -> Transformation d b #(<$) :: a -> Transformation d b -> Transformation d a # Arity (d + 1) => Foldable (Transformation d) Source # Instance detailsDefined in Data.Geometry.Transformation Methodsfold :: Monoid m => Transformation d m -> m #foldMap :: Monoid m => (a -> m) -> Transformation d a -> m #foldMap' :: Monoid m => (a -> m) -> Transformation d a -> m #foldr :: (a -> b -> b) -> b -> Transformation d a -> b #foldr' :: (a -> b -> b) -> b -> Transformation d a -> b #foldl :: (b -> a -> b) -> b -> Transformation d a -> b #foldl' :: (b -> a -> b) -> b -> Transformation d a -> b #foldr1 :: (a -> a -> a) -> Transformation d a -> a #foldl1 :: (a -> a -> a) -> Transformation d a -> a #toList :: Transformation d a -> [a] #null :: Transformation d a -> Bool #length :: Transformation d a -> Int #elem :: Eq a => a -> Transformation d a -> Bool #maximum :: Ord a => Transformation d a -> a #minimum :: Ord a => Transformation d a -> a #sum :: Num a => Transformation d a -> a #product :: Num a => Transformation d a -> a # Arity (d + 1) => Traversable (Transformation d) Source # Instance detailsDefined in Data.Geometry.Transformation Methodstraverse :: Applicative f => (a -> f b) -> Transformation d a -> f (Transformation d b) #sequenceA :: Applicative f => Transformation d (f a) -> f (Transformation d a) #mapM :: Monad m => (a -> m b) -> Transformation d a -> m (Transformation d b) #sequence :: Monad m => Transformation d (m a) -> m (Transformation d a) # (Eq r, Arity (d + 1)) => Eq (Transformation d r) Source # Instance detailsDefined in Data.Geometry.Transformation Methods(==) :: Transformation d r -> Transformation d r -> Bool #(/=) :: Transformation d r -> Transformation d r -> Bool # (Ord r, Arity (d + 1)) => Ord (Transformation d r) Source # Instance detailsDefined in Data.Geometry.Transformation Methodscompare :: Transformation d r -> Transformation d r -> Ordering #(<) :: Transformation d r -> Transformation d r -> Bool #(<=) :: Transformation d r -> Transformation d r -> Bool #(>) :: Transformation d r -> Transformation d r -> Bool #(>=) :: Transformation d r -> Transformation d r -> Bool #max :: Transformation d r -> Transformation d r -> Transformation d r #min :: Transformation d r -> Transformation d r -> Transformation d r # (Show r, Arity (d + 1)) => Show (Transformation d r) Source # Instance detailsDefined in Data.Geometry.Transformation MethodsshowsPrec :: Int -> Transformation d r -> ShowS #show :: Transformation d r -> String #showList :: [Transformation d r] -> ShowS # type NumType (Transformation d r) Source # Instance detailsDefined in Data.Geometry.Transformation type NumType (Transformation d r) = r transformationMatrix :: Iso (Transformation d r) (Transformation d s) (Matrix (d + 1) (d + 1) r) (Matrix (d + 1) (d + 1) s) Source # Transformations and Matrices are isomorphic. (|.|) :: (Num r, Arity (d + 1)) => Transformation d r -> Transformation d r -> Transformation d r Source # Compose transformations (right to left) inverseOf :: (Fractional r, Invertible (d + 1) r) => 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))}


Transformable geometry objects

class IsTransformable g where Source #

A class representing types that can be transformed using a transformation

Methods

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

Instances

Instances details
 Source # Instance detailsDefined in Data.Geometry.Boundary MethodstransformBy :: Transformation (Dimension (Boundary g)) (NumType (Boundary g)) -> Boundary g -> Boundary g Source # Num r => IsTransformable (Ellipse r) Source # Instance detailsDefined in Data.Geometry.Ellipse MethodstransformBy :: Transformation (Dimension (Ellipse r)) (NumType (Ellipse r)) -> Ellipse r -> Ellipse r Source # (Fractional r, Arity d, Arity (d + 1)) => IsTransformable (Vector d r) Source # Instance detailsDefined in Data.Geometry.Transformation MethodstransformBy :: Transformation (Dimension (Vector d r)) (NumType (Vector d r)) -> Vector d r -> Vector d r Source # (Fractional r, Arity d, Arity (d + 1)) => IsTransformable (Point d r) Source # Instance detailsDefined in Data.Geometry.Transformation MethodstransformBy :: Transformation (Dimension (Point d r)) (NumType (Point d r)) -> Point d r -> Point d r Source # (Fractional r, Arity d, Arity (d + 1)) => IsTransformable (Line d r) Source # Lines are transformable, via line segments Instance detailsDefined in Data.Geometry.Line MethodstransformBy :: Transformation (Dimension (Line d r)) (NumType (Line d r)) -> Line d r -> Line d r Source # (Arity d, Arity (d + 1), Fractional r) => IsTransformable (HyperPlane d r) Source # Instance detailsDefined in Data.Geometry.HyperPlane MethodstransformBy :: Transformation (Dimension (HyperPlane d r)) (NumType (HyperPlane d r)) -> HyperPlane d r -> HyperPlane d r Source # (Fractional r, Arity d, Arity (d + 1)) => IsTransformable (HalfLine d r) Source # Instance detailsDefined in Data.Geometry.HalfLine MethodstransformBy :: Transformation (Dimension (HalfLine d r)) (NumType (HalfLine d r)) -> HalfLine d r -> HalfLine d r Source # (Arity d, Arity (d + 1), Fractional r) => IsTransformable (HalfSpace d r) Source # Instance detailsDefined in Data.Geometry.HalfSpace MethodstransformBy :: Transformation (Dimension (HalfSpace d r)) (NumType (HalfSpace d r)) -> HalfSpace d r -> HalfSpace d r Source # Source # Instance detailsDefined in Data.Geometry.Polygon.Convex MethodstransformBy :: Transformation (Dimension (ConvexPolygon p r)) (NumType (ConvexPolygon p r)) -> ConvexPolygon p r -> ConvexPolygon p r Source # (Fractional r, Arity d, Arity (d + 1)) => IsTransformable (Box d p r) Source # Instance detailsDefined in Data.Geometry.Box.Internal MethodstransformBy :: Transformation (Dimension (Box d p r)) (NumType (Box d p r)) -> Box d p r -> Box d p r Source # (Fractional r, Arity d, Arity (d + 1)) => IsTransformable (LineSegment d p r) Source # Instance detailsDefined in Data.Geometry.LineSegment.Internal MethodstransformBy :: Transformation (Dimension (LineSegment d p r)) (NumType (LineSegment d p r)) -> LineSegment d p r -> LineSegment d p r Source # (Fractional r, Arity d, Arity (d + 1)) => IsTransformable (PolyLine d p r) Source # Instance detailsDefined in Data.Geometry.PolyLine MethodstransformBy :: Transformation (Dimension (PolyLine d p r)) (NumType (PolyLine d p r)) -> PolyLine d p r -> PolyLine d p r Source # (Fractional r, Arity d, Arity (d + 1), Arity n) => IsTransformable (BezierSpline n d r) Source # Instance detailsDefined in Data.Geometry.BezierSpline MethodstransformBy :: Transformation (Dimension (BezierSpline n d r)) (NumType (BezierSpline n d r)) -> BezierSpline n d r -> BezierSpline n d r Source # (Fractional r, Arity d, Arity (d + 1)) => IsTransformable (Triangle d p r) Source # Instance detailsDefined in Data.Geometry.Triangle MethodstransformBy :: Transformation (Dimension (Triangle d p r)) (NumType (Triangle d p r)) -> Triangle d p r -> Triangle d p r Source # Fractional r => IsTransformable (Polygon t p r) Source # Instance detailsDefined in Data.Geometry.Polygon.Core MethodstransformBy :: Transformation (Dimension (Polygon t p r)) (NumType (Polygon t p r)) -> Polygon t p r -> Polygon t p r Source #

transformAllBy :: (Functor c, IsTransformable g) => Transformation (Dimension g) (NumType g) -> c g -> c g Source #

Apply a transformation to a collection of objects.

>>> transformAllBy (uniformScaling 2) [Point1 1, Point1 2, Point1 3]
[Point1 2.0,Point1 4.0,Point1 6.0]


transformPointFunctor :: (PointFunctor g, Fractional r, d ~ Dimension (g r), Arity d, Arity (d + 1)) => Transformation d r -> g r -> g r Source #

Apply transformation to a PointFunctor, ie something that contains points. Polygons, triangles, line segments, etc, are all PointFunctors.

>>> transformPointFunctor (uniformScaling 2) $OpenLineSegment (Point1 1 :+ ()) (Point1 2 :+ ()) OpenLineSegment (Point1 2.0 :+ ()) (Point1 4.0 :+ ())  Common transformations translation :: (Num r, Arity d, Arity (d + 1)) => Vector d r -> Transformation d r Source # Create translation transformation from a vector. >>> transformBy (translation$ Vector2 1 2) $Point2 2 3 Point2 3.0 5.0  scaling :: (Num r, Arity d, Arity (d + 1)) => Vector d r -> Transformation d r Source # Create scaling transformation from a vector. >>> transformBy (scaling$ Vector2 2 (-1)) $Point2 2 3 Point2 4.0 (-3.0)  uniformScaling :: (Num r, Arity d, Arity (d + 1)) => 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


Functions that execute transformations

translateBy :: (IsTransformable g, Num (NumType g), Arity (Dimension g), Arity (Dimension g + 1)) => Vector (Dimension g) (NumType g) -> g -> g Source #

Translate a given point.

>>> translateBy (Vector2 1 2) $Point2 2 3 Point2 3.0 5.0  scaleBy :: (IsTransformable g, Num (NumType g), Arity (Dimension g), Arity (Dimension g + 1)) => Vector (Dimension g) (NumType g) -> g -> g Source # Scale a given point. >>> scaleBy (Vector2 2 (-1))$ Point2 2 3
Point2 4.0 (-3.0)


scaleUniformlyBy :: (IsTransformable g, Num (NumType g), Arity (Dimension g), Arity (Dimension g + 1)) => NumType g -> g -> g Source #

Scale a given point uniformly in all dimensions.

>>> scaleUniformlyBy 5 $Point2 2 3 Point2 10.0 15.0  transRow :: forall n r. (Arity n, Arity (n + 1), Num r) => Int -> r -> Vector (n + 1) r Source # Row in a translation matrix transRow :: forall n r. ( Arity n, Arity (n- 1), ((n - 1) + 1) ~ n , Num r) => Int -> r -> Vector n r transRow i x = set (V.element (Proxy :: Proxy (n-1))) x$ mkRow i 1

3D Rotations

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.

2D Transformations

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

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