vect-floating-0.1.0.4: A low-dimensional linear algebra library, operating on the Floating typeclass

Data.Vect.Floating.Base

Synopsis

# Documentation

class AbelianGroup g where Source

Methods

(&+) :: g -> g -> g infixl 6 Source

(&-) :: g -> g -> g infixl 6 Source

neg :: g -> g Source

zero :: g Source

Instances

 Floating a => AbelianGroup (Mat4 a) Floating a => AbelianGroup (Mat3 a) Floating a => AbelianGroup (Mat2 a) Floating a => AbelianGroup (Vec4 a) Floating a => AbelianGroup (Vec3 a) Floating a => AbelianGroup (Vec2 a) Floating a => AbelianGroup (Quaternion a)

vecSum :: AbelianGroup g => [g] -> g Source

class MultSemiGroup r where Source

Methods

(.*.) :: r -> r -> r infixl 7 Source

one :: r Source

Instances

 Floating a => MultSemiGroup (Proj4 a) Floating a => MultSemiGroup (Proj3 a) Floating a => MultSemiGroup (Ortho4 a) Floating a => MultSemiGroup (Ortho3 a) Floating a => MultSemiGroup (Ortho2 a) Floating a => MultSemiGroup (Mat4 a) Floating a => MultSemiGroup (Mat3 a) Floating a => MultSemiGroup (Mat2 a) Floating a => MultSemiGroup (UnitQuaternion a) Num a => MultSemiGroup (Quaternion a)

class (AbelianGroup r, MultSemiGroup r) => Ring r Source

Instances

 Floating a => Ring (Mat4 a) Floating a => Ring (Mat3 a) Floating a => Ring (Mat2 a)

class LeftModule r m where Source

Minimal complete definition

lmul

Methods

lmul :: r -> m -> m Source

(*.) :: r -> m -> m infixr 7 Source

Instances

 Floating a => LeftModule (Mat4 a) (Vec4 a) Floating a => LeftModule (Mat3 a) (Vec3 a) Floating a => LeftModule (Mat2 a) (Vec2 a) Num a => LeftModule (UnitQuaternion a) (Vec3 a)

class RightModule m r | m -> r, r -> m where Source

Minimal complete definition

rmul

Methods

rmul :: m -> r -> m Source

(.*) :: m -> r -> m infixl 7 Source

Instances

 Floating a => RightModule (Vec4 a) (Mat4 a) Floating a => RightModule (Vec3 a) (Mat3 a) Floating a => RightModule (Vec2 a) (Mat2 a)

class AbelianGroup (v a) => Vector a v where Source

Minimal complete definition

Methods

mapVec :: (a -> a) -> v a -> v a Source

scalarMul :: a -> v a -> v a Source

(*&) :: a -> v a -> v a infixr 7 Source

(&*) :: v a -> a -> v a infixl 7 Source

Instances

 Floating a => Vector a Mat4 Floating a => Vector a Vec4 Floating a => Vector a Mat3 Floating a => Vector a Vec3 Floating a => Vector a Mat2 Floating a => Vector a Vec2 Floating a => Vector a Quaternion

class Floating a => DotProd a v where Source

Minimal complete definition

(&.)

Methods

(&.) :: v a -> v a -> a infix 7 Source

norm :: v a -> a Source

normsqr :: v a -> a Source

len :: v a -> a Source

lensqr :: v a -> a Source

dotprod :: v a -> v a -> a Source

Instances

 Floating a => DotProd a Vec4 Floating a => DotProd a Vec3 Floating a => DotProd a Vec2 Floating a => DotProd a Normal4 Floating a => DotProd a Normal3 Floating a => DotProd a Normal2 Floating a => DotProd a UnitQuaternion Floating a => DotProd a Quaternion

class CrossProd v where Source

Cross product

Minimal complete definition

crossprod

Methods

crossprod :: v -> v -> v Source

(&^) :: v -> v -> v infix 7 Source

Instances

 Floating a => CrossProd (Normal3 a) Floating a => CrossProd (Vec3 a)

normalize :: (Vector a v, DotProd a v) => v a -> v a Source

distance :: (Vector a v, DotProd a v) => v a -> v a -> a Source

angle :: (Vector a v, DotProd a v) => v a -> v a -> a Source

the angle between two vectors

angle' :: (Vector a v, UnitVector a v u, DotProd a v) => u a -> u a -> a Source

the angle between two unit vectors

class (Vector a v, DotProd a v) => UnitVector a v u | u -> v, v -> u where Source

Minimal complete definition

Methods

Arguments

 :: v a -> u a normalizes the input

Arguments

 :: v a -> u a does not normalize the input!

fromNormal :: u a -> v a Source

fromNormalRadius :: a -> u a -> v a Source

Instances

 Floating a => UnitVector a Vec4 Normal4 Floating a => UnitVector a Vec3 Normal3 Floating a => UnitVector a Vec2 Normal2 Floating a => UnitVector a Quaternion UnitQuaternion

class Pointwise v where Source

Pointwise multiplication

Minimal complete definition

pointwise

Methods

pointwise :: v -> v -> v Source

(&!) :: v -> v -> v infix 7 Source

Instances

 Floating a => Pointwise (Mat4 a) Floating a => Pointwise (Mat3 a) Floating a => Pointwise (Mat2 a) Num a => Pointwise (Vec4 a) Num a => Pointwise (Vec3 a) Floating a => Pointwise (Vec2 a)

class Extend a u v where Source

conversion between vectors (and matrices) of different dimensions

Methods

Arguments

 :: u a -> v a example: `extendZero (Vec2 5 6) = Vec4 5 6 0 0`

Arguments

 :: a -> u a -> v a example: `extendWith 1 (Vec2 5 6) = Vec4 5 6 1 1`

Arguments

 :: v a -> u a example: `trim (Vec4 5 6 7 8) = Vec2 5 6`

Instances

 Floating a => Extend a Mat3 Mat4 Floating a => Extend a Mat2 Mat4 Floating a => Extend a Mat2 Mat3 Floating a => Extend a Vec3 Vec4 Floating a => Extend a Vec2 Vec4 Floating a => Extend a Vec2 Vec3

class HasCoordinates v x | v -> x where Source

Minimal complete definition

Nothing

Methods

_1 :: v -> x Source

_2 :: v -> x Source

_3 :: v -> x Source

_4 :: v -> x Source

Instances

 Floating a => HasCoordinates (Vec4 a) a Floating a => HasCoordinates (Vec3 a) a Floating a => HasCoordinates (Vec2 a) a Floating a => HasCoordinates (Mat4 a) (Vec4 a) Floating a => HasCoordinates (Mat3 a) (Vec3 a) Floating a => HasCoordinates (Mat2 a) (Vec2 a)

class Dimension a where Source

Methods

dim :: a -> Int Source

Instances

 Floating a => Dimension (Ortho4 a) Floating a => Dimension (Ortho3 a) Floating a => Dimension (Ortho2 a) Floating a => Dimension (Normal4 a) Floating a => Dimension (Normal3 a) Floating a => Dimension (Normal2 a) Floating a => Dimension (Mat4 a) Floating a => Dimension (Mat3 a) Floating a => Dimension (Mat2 a) Floating a => Dimension (Vec4 a) Floating a => Dimension (Vec3 a) Floating a => Dimension (Vec2 a)

class Matrix m where Source

Methods

transpose :: m -> m Source

inverse :: m -> m Source

idmtx :: m Source

Instances

 Floating a => Matrix (Proj4 a) Floating a => Matrix (Proj3 a) Floating a => Matrix (Ortho4 a) Floating a => Matrix (Ortho3 a) Floating a => Matrix (Ortho2 a) Floating a => Matrix (Mat4 a) Floating a => Matrix (Mat3 a) Floating a => Matrix (Mat2 a)

class Tensor t v | t -> v where Source

Outer product (could be unified with Diagonal?)

Methods

outer :: v -> v -> t Source

Instances

 Floating a => Tensor (Mat4 a) (Vec4 a) Floating a => Tensor (Mat3 a) (Vec3 a) Floating a => Tensor (Mat2 a) (Vec2 a)

class Diagonal s t | t -> s where Source

makes a diagonal matrix from a vector

Methods

diag :: s -> t Source

Instances

 Floating a => Diagonal (Vec4 a) (Mat4 a) Floating a => Diagonal (Vec3 a) (Mat3 a) Floating a => Diagonal (Vec2 a) (Mat2 a)

class Determinant a m where Source

Methods

det :: m -> a Source

Instances

 Floating a => Determinant a (Mat4 a) Floating a => Determinant a (Mat3 a) Floating a => Determinant a (Mat2 a) Floating a => Determinant a (Ortho2 a) Floating a => Determinant a (Ortho3 a) Floating a => Determinant a (Ortho4 a) Floating a => Determinant a (Vec2 a, Vec2 a) Floating a => Determinant a (Vec3 a, Vec3 a, Vec3 a)

class Matrix (m a) => Orthogonal a m o | m -> o, o -> m where Source

Methods

fromOrtho :: o a -> m a Source

toOrthoUnsafe :: m a -> o a Source

Instances

 Floating a => Orthogonal a Mat4 Ortho4 Floating a => Orthogonal a Mat3 Ortho3 Floating a => Orthogonal a Mat2 Ortho2

class (Vector a v, Orthogonal a n o, Diagonal (v a) (n a)) => Projective a v n o m p | m -> p, p -> m, p -> o, o -> p, p -> n, n -> p, p -> v, v -> p, n -> o, n -> v, v -> n where Source

"Projective" matrices have the following form: the top left corner is an any matrix, the bottom right corner is 1, and the top-right column is zero. These describe the affine orthogonal transformation of the space one dimension less.

Methods

fromProjective :: p a -> m a Source

toProjectiveUnsafe :: m a -> p a Source

orthogonal :: o a -> p a Source

linear :: n a -> p a Source

translation :: v a -> p a Source

scaling :: v a -> p a Source

Instances

 Floating a => Projective a Vec3 Mat3 Ortho3 Mat4 Proj4 Floating a => Projective a Vec2 Mat2 Ortho2 Mat3 Proj3

class (AbelianGroup m, Matrix m) => MatrixNorms a m where Source

Minimal complete definition

frobeniusNorm

Methods

Arguments

 :: m -> a the frobenius norm (= euclidean norm in the space of matrices)

Arguments

 :: m -> m -> a euclidean distance in the space of matrices

Arguments

 :: m -> a (euclidean) operator norm (not implemented yet)

Instances

 Floating a => MatrixNorms a (Mat4 a) Floating a => MatrixNorms a (Mat3 a) Floating a => MatrixNorms a (Mat2 a)

data Vec2 a Source

Constructors

 Vec2 !a !a

Instances

 Floating a => DotProd a Vec2 Floating a => Vector a Vec2 Floating a => Extend a Vec2 Vec4 Floating a => Extend a Vec2 Vec3 Floating a => UnitVector a Vec2 Normal2 Floating a => Projective a Vec2 Mat2 Ortho2 Mat3 Proj3 Floating a => Interpolate a (Vec2 a) Floating a => Determinant a (Vec2 a, Vec2 a) Read a => Read (Vec2 a) Show a => Show (Vec2 a) (Floating a, Storable a) => Storable (Vec2 a) (Floating a, Random a) => Random (Vec2 a) Floating a => Dimension (Vec2 a) Floating a => Pointwise (Vec2 a) Floating a => AbelianGroup (Vec2 a) Floating a => HasCoordinates (Vec2 a) a Floating a => Tensor (Mat2 a) (Vec2 a) Floating a => Diagonal (Vec2 a) (Mat2 a) Floating a => HasCoordinates (Mat2 a) (Vec2 a) Floating a => RightModule (Vec2 a) (Mat2 a) Floating a => LeftModule (Mat2 a) (Vec2 a) Floating a => GramSchmidt (Vec2 a, Vec2 a) Typeable (* -> *) Vec2

data Vec3 a Source

Constructors

 Vec3 !a !a !a

Instances

 Floating a => DotProd a Vec3 Floating a => Vector a Vec3 Floating a => Extend a Vec3 Vec4 Floating a => Extend a Vec2 Vec3 Floating a => UnitVector a Vec3 Normal3 Floating a => Projective a Vec3 Mat3 Ortho3 Mat4 Proj4 Floating a => Interpolate a (Vec3 a) Floating a => Determinant a (Vec3 a, Vec3 a, Vec3 a) Read a => Read (Vec3 a) Show a => Show (Vec3 a) (Floating a, Storable a) => Storable (Vec3 a) (Floating a, Random a) => Random (Vec3 a) Floating a => Dimension (Vec3 a) Num a => Pointwise (Vec3 a) Floating a => CrossProd (Vec3 a) Floating a => AbelianGroup (Vec3 a) Floating a => HasCoordinates (Vec3 a) a Floating a => Tensor (Mat3 a) (Vec3 a) Floating a => Diagonal (Vec3 a) (Mat3 a) Floating a => HasCoordinates (Mat3 a) (Vec3 a) Floating a => RightModule (Vec3 a) (Mat3 a) Floating a => LeftModule (Mat3 a) (Vec3 a) Num a => LeftModule (UnitQuaternion a) (Vec3 a) Floating a => GramSchmidt (Vec3 a, Vec3 a) Typeable (* -> *) Vec3 Floating a => GramSchmidt (Vec3 a, Vec3 a, Vec3 a)

data Vec4 a Source

Constructors

 Vec4 !a !a !a !a

Instances

 Floating a => DotProd a Vec4 Floating a => Vector a Vec4 Floating a => Extend a Vec3 Vec4 Floating a => Extend a Vec2 Vec4 Floating a => UnitVector a Vec4 Normal4 Floating a => Interpolate a (Vec4 a) Read a => Read (Vec4 a) Show a => Show (Vec4 a) (Floating a, Storable a) => Storable (Vec4 a) (Floating a, Random a) => Random (Vec4 a) Floating a => Dimension (Vec4 a) Num a => Pointwise (Vec4 a) Floating a => AbelianGroup (Vec4 a) Floating a => HasCoordinates (Vec4 a) a Floating a => Tensor (Mat4 a) (Vec4 a) Floating a => Diagonal (Vec4 a) (Mat4 a) Floating a => HasCoordinates (Mat4 a) (Vec4 a) Floating a => RightModule (Vec4 a) (Mat4 a) Floating a => LeftModule (Mat4 a) (Vec4 a) Floating a => GramSchmidt (Vec4 a, Vec4 a) Typeable (* -> *) Vec4 Floating a => GramSchmidt (Vec4 a, Vec4 a, Vec4 a) Floating a => GramSchmidt (Vec4 a, Vec4 a, Vec4 a, Vec4 a)

data Mat2 a Source

The components are row vectors

Constructors

 Mat2 !(Vec2 a) !(Vec2 a)

Instances

 Floating a => Vector a Mat2 Floating a => Orthogonal a Mat2 Ortho2 Floating a => Extend a Mat2 Mat4 Floating a => Extend a Mat2 Mat3 Floating a => Projective a Vec2 Mat2 Ortho2 Mat3 Proj3 Floating a => Determinant a (Mat2 a) Floating a => MatrixNorms a (Mat2 a) Read a => Read (Mat2 a) Show a => Show (Mat2 a) (Floating a, Storable a) => Storable (Mat2 a) (Floating a, Random a) => Random (Mat2 a) Floating a => Dimension (Mat2 a) Floating a => Matrix (Mat2 a) Floating a => Pointwise (Mat2 a) Floating a => Ring (Mat2 a) Floating a => MultSemiGroup (Mat2 a) Floating a => AbelianGroup (Mat2 a) Floating a => Tensor (Mat2 a) (Vec2 a) Floating a => Diagonal (Vec2 a) (Mat2 a) Floating a => HasCoordinates (Mat2 a) (Vec2 a) Floating a => RightModule (Vec2 a) (Mat2 a) Floating a => LeftModule (Mat2 a) (Vec2 a)

data Mat3 a Source

Constructors

 Mat3 !(Vec3 a) !(Vec3 a) !(Vec3 a)

Instances

 Floating a => Vector a Mat3 Floating a => Orthogonal a Mat3 Ortho3 Floating a => Extend a Mat3 Mat4 Floating a => Extend a Mat2 Mat3 Floating a => Projective a Vec3 Mat3 Ortho3 Mat4 Proj4 Floating a => Projective a Vec2 Mat2 Ortho2 Mat3 Proj3 Floating a => Determinant a (Mat3 a) Floating a => MatrixNorms a (Mat3 a) Read a => Read (Mat3 a) Show a => Show (Mat3 a) (Floating a, Storable a) => Storable (Mat3 a) (Floating a, Random a) => Random (Mat3 a) Floating a => Dimension (Mat3 a) Floating a => Matrix (Mat3 a) Floating a => Pointwise (Mat3 a) Floating a => Ring (Mat3 a) Floating a => MultSemiGroup (Mat3 a) Floating a => AbelianGroup (Mat3 a) Floating a => Tensor (Mat3 a) (Vec3 a) Floating a => Diagonal (Vec3 a) (Mat3 a) Floating a => HasCoordinates (Mat3 a) (Vec3 a) Floating a => RightModule (Vec3 a) (Mat3 a) Floating a => LeftModule (Mat3 a) (Vec3 a)

data Mat4 a Source

Constructors

 Mat4 !(Vec4 a) !(Vec4 a) !(Vec4 a) !(Vec4 a)

Instances

 Floating a => Vector a Mat4 Floating a => Orthogonal a Mat4 Ortho4 Floating a => Extend a Mat3 Mat4 Floating a => Extend a Mat2 Mat4 Floating a => Projective a Vec3 Mat3 Ortho3 Mat4 Proj4 Floating a => Determinant a (Mat4 a) Floating a => MatrixNorms a (Mat4 a) Read a => Read (Mat4 a) Show a => Show (Mat4 a) (Floating a, Storable a) => Storable (Mat4 a) (Floating a, Random a) => Random (Mat4 a) Floating a => Dimension (Mat4 a) Floating a => Matrix (Mat4 a) Floating a => Pointwise (Mat4 a) Floating a => Ring (Mat4 a) Floating a => MultSemiGroup (Mat4 a) Floating a => AbelianGroup (Mat4 a) Floating a => Tensor (Mat4 a) (Vec4 a) Floating a => Diagonal (Vec4 a) (Mat4 a) Floating a => HasCoordinates (Mat4 a) (Vec4 a) Floating a => RightModule (Vec4 a) (Mat4 a) Floating a => LeftModule (Mat4 a) (Vec4 a)

data Ortho2 a Source

Orthogonal matrices.

Note: the Random instances generates orthogonal matrices with determinant 1 (that is, orientation-preserving orthogonal transformations)!

Instances

 Floating a => Orthogonal a Mat2 Ortho2 Floating a => Projective a Vec2 Mat2 Ortho2 Mat3 Proj3 Floating a => Determinant a (Ortho2 a) Read a => Read (Ortho2 a) Show a => Show (Ortho2 a) (Floating a, Storable a) => Storable (Ortho2 a) (Floating a, Ord a, Random a) => Random (Ortho2 a) Floating a => Dimension (Ortho2 a) Floating a => Matrix (Ortho2 a) Floating a => MultSemiGroup (Ortho2 a)

data Ortho3 a Source

Instances

 Floating a => Orthogonal a Mat3 Ortho3 Floating a => Projective a Vec3 Mat3 Ortho3 Mat4 Proj4 Floating a => Determinant a (Ortho3 a) Read a => Read (Ortho3 a) Show a => Show (Ortho3 a) (Floating a, Storable a) => Storable (Ortho3 a) (Floating a, Ord a, Random a) => Random (Ortho3 a) Floating a => Dimension (Ortho3 a) Floating a => Matrix (Ortho3 a) Floating a => MultSemiGroup (Ortho3 a)

data Ortho4 a Source

Instances

 Floating a => Orthogonal a Mat4 Ortho4 Floating a => Determinant a (Ortho4 a) Read a => Read (Ortho4 a) Show a => Show (Ortho4 a) (Floating a, Storable a) => Storable (Ortho4 a) (Floating a, Ord a, Random a) => Random (Ortho4 a) Floating a => Dimension (Ortho4 a) Floating a => Matrix (Ortho4 a) Floating a => MultSemiGroup (Ortho4 a)

data Normal2 a Source

The assumption when dealing with these is always that they are of unit length. Also, interpolation works differently.

Instances

 Floating a => DotProd a Normal2 Floating a => UnitVector a Vec2 Normal2 Floating a => Interpolate a (Normal2 a) Read a => Read (Normal2 a) Show a => Show (Normal2 a) (Floating a, Storable a) => Storable (Normal2 a) (Floating a, Random a, Ord a) => Random (Normal2 a) Floating a => Dimension (Normal2 a) Floating a => GramSchmidt (Normal2 a, Normal2 a) Typeable (* -> *) Normal2

data Normal3 a Source

Instances

 Floating a => DotProd a Normal3 Floating a => UnitVector a Vec3 Normal3 Floating a => Interpolate a (Normal3 a) Read a => Read (Normal3 a) Show a => Show (Normal3 a) (Floating a, Storable a) => Storable (Normal3 a) (Floating a, Random a, Ord a) => Random (Normal3 a) Floating a => Dimension (Normal3 a) Floating a => CrossProd (Normal3 a) Floating a => GramSchmidt (Normal3 a, Normal3 a) Typeable (* -> *) Normal3 Floating a => GramSchmidt (Normal3 a, Normal3 a, Normal3 a)

data Normal4 a Source

Instances

 Floating a => DotProd a Normal4 Floating a => UnitVector a Vec4 Normal4 Floating a => Interpolate a (Normal4 a) Read a => Read (Normal4 a) Show a => Show (Normal4 a) (Floating a, Storable a) => Storable (Normal4 a) (Floating a, Random a, Ord a) => Random (Normal4 a) Floating a => Dimension (Normal4 a) Floating a => GramSchmidt (Normal4 a, Normal4 a) Typeable (* -> *) Normal4 Floating a => GramSchmidt (Normal4 a, Normal4 a, Normal4 a) Floating a => GramSchmidt (Normal4 a, Normal4 a, Normal4 a, Normal4 a)

data Proj3 a Source

Projective matrices, encoding affine transformations in dimension one less.

Instances

 Floating a => Projective a Vec2 Mat2 Ortho2 Mat3 Proj3 Read a => Read (Proj3 a) Show a => Show (Proj3 a) (Floating a, Storable a) => Storable (Proj3 a) Floating a => Matrix (Proj3 a) Floating a => MultSemiGroup (Proj3 a)

data Proj4 a Source

Instances

 Floating a => Projective a Vec3 Mat3 Ortho3 Mat4 Proj4 Read a => Read (Proj4 a) Show a => Show (Proj4 a) (Floating a, Storable a) => Storable (Proj4 a) Floating a => Matrix (Proj4 a) Floating a => MultSemiGroup (Proj4 a)

mkVec2 :: (a, a) -> Vec2 a Source

mkVec3 :: (a, a, a) -> Vec3 a Source

mkVec4 :: (a, a, a, a) -> Vec4 a Source

project :: (Vector a v, DotProd a v) => v a -> v a -> v a Source

project' :: (Vector a v, UnitVector a v u, DotProd a v) => v a -> u a -> v a Source

Projects the first vector down to the hyperplane orthogonal to the second (unit) vector

projectUnsafe :: (Vector a v, DotProd a v) => v a -> v a -> v a Source

Direction (second argument) is assumed to be a unit vector!

flipNormal :: UnitVector a v n => n a -> n a Source

Since unit vectors are not a group, we need a separate function.

householder :: (Vector a v, UnitVector a v u, Matrix (m a), Vector a m, Tensor (m a) (v a)) => u a -> m a Source

Householder matrix, see http://en.wikipedia.org/wiki/Householder_transformation. In plain words, it is the reflection to the hyperplane orthogonal to the input vector.

householderOrtho :: (Vector a v, UnitVector a v u, Matrix (m a), Vector a m, Tensor (m a) (v a), Orthogonal a m o) => u a -> o a Source