Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
This module provides functionality for working with affine transformations (i.e. in the unit square)
- data Point a = Point {}
- mkPoint :: a -> a -> Point a
- setPointX :: a -> Point a -> Point a
- setPointY :: a -> Point a -> Point a
- data LabeledPoint l a = LabeledPoint {}
- mkLabeledPoint :: Point a -> l -> LabeledPoint l a
- labelPoint :: (Point a -> l) -> Point a -> LabeledPoint l a
- mapLabel :: (l1 -> l2) -> LabeledPoint l1 a -> LabeledPoint l2 a
- data Frame a = Frame {}
- mkFrame :: Point a -> Point a -> Frame a
- unitFrame :: Num a => Frame a
- frameFromPoints :: (Ord a, Foldable t, Functor t) => t (Point a) -> Frame a
- mkFrameOrigin :: Num a => a -> a -> Frame a
- height :: Num a => Frame a -> a
- width :: Num a => Frame a -> a
- xmin :: Frame a -> a
- xmax :: Frame a -> a
- ymin :: Frame a -> a
- ymax :: Frame a -> a
- isPointInFrame :: Ord a => Frame a -> Point a -> Bool
- data Axis
- otherAxis :: Axis -> Axis
- data V2 a = V2 a a
- pointFromV2 :: V2 a -> Point a
- data Mat2 a = Mat2 a a a a
- data DiagMat2 a = DMat2 a a
- diagMat2 :: Num a => a -> a -> DiagMat2 a
- origin :: Num a => Point a
- oneOne :: Num a => Point a
- e1 :: Num a => V2 a
- e2 :: Num a => V2 a
- norm2 :: (Hermitian v, Floating n, n ~ InnerProduct v) => v -> n
- normalize2 :: (InnerProduct v ~ Scalar v, Floating (Scalar v), Hermitian v) => v -> v
- v2fromEndpoints :: Num a => Point a -> Point a -> V2 a
- v2fromPoint :: Num a => Point a -> V2 a
- movePoint :: Num a => V2 a -> Point a -> Point a
- moveLabeledPoint :: (Point a -> Point b) -> LabeledPoint l a -> LabeledPoint l b
- moveLabeledPointV2 :: Num a => V2 a -> LabeledPoint l a -> LabeledPoint l a
- moveLabeledPointBwFrames :: Fractional a => Frame a -> Frame a -> Bool -> Bool -> LabeledPoint l a -> LabeledPoint l a
- (-.) :: Num a => Point a -> Point a -> V2 a
- pointRange :: (Fractional a, Integral n) => n -> Point a -> Point a -> [Point a]
- frameToFrame :: Fractional a => Frame a -> Frame a -> Bool -> Bool -> V2 a -> V2 a
- frameToFrameValue :: Fractional t => Frame t -> Frame t -> t -> t
- class AdditiveGroup v where
- class AdditiveGroup v => VectorSpace v where
- class VectorSpace v => Hermitian v where
- type InnerProduct v :: *
- class Hermitian v => LinearMap m v where
- class MultiplicativeSemigroup m where
- class LinearMap m v => MatrixGroup m v where
- class Eps a where
- meshGrid :: (Enum a, RealFrac a) => Frame a -> Int -> Int -> [Point a]
- subdivSegment :: (Real a, Enum b, RealFrac b) => a -> a -> Int -> [b]
- interpolateBilinear :: (Ord p, Fractional p, Show p) => Frame p -> (Point p -> p) -> Point p -> p
Geometry
Point
A Point
object defines a point in the plane
LabeledPoint
data LabeledPoint l a Source #
A LabeledPoint
carries a "label" (i.e. any additional information such as a text tag, or any other data structure), in addition to position information. Data points on a plot are LabeledPoint
s.
LabeledPoint | |
|
mkLabeledPoint :: Point a -> l -> LabeledPoint l a Source #
labelPoint :: (Point a -> l) -> Point a -> LabeledPoint l a Source #
Given a labelling function and a Point
p
, returned a LabeledPoint
containing p
and the computed label
mapLabel :: (l1 -> l2) -> LabeledPoint l1 a -> LabeledPoint l2 a Source #
Apply a function to the label
Frame
A frame, i.e. a bounding box for objects
mkFrameOrigin :: Num a => a -> a -> Frame a Source #
Build a frame rooted at the origin (0, 0)
Axis
Vectors
V2 is a vector in R^2
V2 a a |
Eq a => Eq (V2 a) Source # | |
Show a => Show (V2 a) Source # | |
Num a => Semigroup (V2 a) Source # | |
Num a => Monoid (V2 a) Source # | Vectors form a monoid w.r.t. vector addition |
Eps (V2 Double) Source # | |
Eps (V2 Float) Source # | |
Num a => Hermitian (V2 a) Source # | |
Num a => VectorSpace (V2 a) Source # | |
Num a => AdditiveGroup (V2 a) Source # | Vectors form an additive group |
Fractional a => MatrixGroup (DiagMat2 a) (V2 a) Source # | Diagonal matrices can always be inverted |
Num a => LinearMap (DiagMat2 a) (V2 a) Source # | |
Num a => LinearMap (Mat2 a) (V2 a) Source # | |
type InnerProduct (V2 a) Source # | |
type Scalar (V2 a) Source # | |
pointFromV2 :: V2 a -> Point a Source #
Matrices
A Mat2 can be seen as a linear operator that acts on points in the plane
Mat2 a a a a |
Eq a => Eq (Mat2 a) Source # | |
Show a => Show (Mat2 a) Source # | |
Num a => Semigroup (Mat2 a) Source # | |
Num a => Monoid (Mat2 a) Source # | Matrices form a monoid w.r.t. matrix multiplication and have the identity matrix as neutral element |
Num a => MultiplicativeSemigroup (Mat2 a) Source # | |
Num a => LinearMap (Mat2 a) (V2 a) Source # | |
Diagonal matrices in R2 behave as scaling transformations
DMat2 a a |
Eq a => Eq (DiagMat2 a) Source # | |
Show a => Show (DiagMat2 a) Source # | |
Num a => Semigroup (DiagMat2 a) Source # | |
Num a => Monoid (DiagMat2 a) Source # | Diagonal matrices form a monoid w.r.t. matrix multiplication and have the identity matrix as neutral element |
Num a => MultiplicativeSemigroup (DiagMat2 a) Source # | |
Fractional a => MatrixGroup (DiagMat2 a) (V2 a) Source # | Diagonal matrices can always be inverted |
Num a => LinearMap (DiagMat2 a) (V2 a) Source # | |
Primitive elements
Vector norm operations
normalize2 :: (InnerProduct v ~ Scalar v, Floating (Scalar v), Hermitian v) => v -> v Source #
Normalize a V2 w.r.t. its Euclidean norm
Vector construction
v2fromEndpoints :: Num a => Point a -> Point a -> V2 a Source #
Create a V2 v
from two endpoints p1, p2. That is v
can be seen as pointing from p1
to p2
Operations on points
moveLabeledPoint :: (Point a -> Point b) -> LabeledPoint l a -> LabeledPoint l b Source #
moveLabeledPointV2 :: Num a => V2 a -> LabeledPoint l a -> LabeledPoint l a Source #
Move a LabeledPoint
along a vector
moveLabeledPointBwFrames Source #
:: Fractional a | |
=> Frame a | Initial frame |
-> Frame a | Final frame |
-> Bool | Flip L-R in [0,1] x [0,1] |
-> Bool | Flip U-D in [0,1] x [0,1] |
-> LabeledPoint l a | Initial |
-> LabeledPoint l a |
(-.) :: Num a => Point a -> Point a -> V2 a Source #
Create a V2 v
from two endpoints p1, p2. That is v
can be seen as pointing from p1
to p2
pointRange :: (Fractional a, Integral n) => n -> Point a -> Point a -> [Point a] Source #
`pointRange n p q` returns a list of equi-spaced Point
s between p
and q
.
Operations on vectors
:: Fractional a | |
=> Frame a | Initial frame |
-> Frame a | Final frame |
-> Bool | Flip L-R in [0,1] x [0,1] |
-> Bool | Flip U-D in [0,1] x [0,1] |
-> V2 a | Initial vector |
-> V2 a |
Given two frames F1
and F2
, returns a function f
that maps an arbitrary vector v
contained within F1
onto one contained within F2
.
This function is composed of three affine maps :
- map
v
into a vectorv01
that points within the unit square, - map
v01
ontov01'
. This transformation serves to e.g. flip the dataset along the y axis (since the origin of the SVG canvas is the top-left corner of the screen). If this is not needed one can just supply the identity matrix and the zero vector, - map
v01'
onto the target frameF2
.
NB: we do not check that v
is actually contained within the F1
, nor that v01'
is still contained within [0,1] x [0, 1]. This has to be supplied correctly by the user.
:: Fractional t | |
=> Frame t | Initial frame |
-> Frame t | Final frame |
-> t | Initial value |
-> t |
Map function values across frames
Typeclasses
class AdditiveGroup v where Source #
Additive group :
v ^+^ zero == zero ^+^ v == v
v ^-^ v == zero
Identity element
Group action ("sum")
Inverse group action ("subtraction")
Num a => AdditiveGroup (V2 a) Source # | Vectors form an additive group |
class AdditiveGroup v => VectorSpace v where Source #
Vector space : multiplication by a scalar quantity
Num a => VectorSpace (V2 a) Source # | |
class VectorSpace v => Hermitian v where Source #
Hermitian space : inner product
type InnerProduct v :: * Source #
(<.>) :: v -> v -> InnerProduct v Source #
Inner product
class Hermitian v => LinearMap m v where Source #
Linear maps, i.e. linear transformations of vectors
class MultiplicativeSemigroup m where Source #
Multiplicative matrix semigroup ("multiplying" two matrices together)
Num a => MultiplicativeSemigroup (DiagMat2 a) Source # | |
Num a => MultiplicativeSemigroup (Mat2 a) Source # | |
class LinearMap m v => MatrixGroup m v where Source #
The class of invertible linear transformations
Fractional a => MatrixGroup (DiagMat2 a) (V2 a) Source # | Diagonal matrices can always be inverted |
Numerical equality
Utilities
A list of nx
by ny
points in the plane arranged on the vertices of a rectangular mesh.
NB: Only the minimum x, y coordinate point is included in the output mesh. This is intentional, since the output from this can be used as an input to functions that use a corner rather than the center point as refernce (e.g. rect
)
interpolateBilinear :: (Ord p, Fractional p, Show p) => Frame p -> (Point p -> p) -> Point p -> p Source #
Interpolation
Safe