simple-vec3-0.4.0.9: Three-dimensional vectors of doubles with basic operations

Safe HaskellNone
LanguageHaskell2010

Data.Vec3.Class

Synopsis

Documentation

class Vec3 v where #

Three-dimensional vector, with an associated matrix type.

Minimal complete definition

fromXYZ, toXYZ, fromRows, toRows

Associated Types

data Matrix v #

Associated type for 3×3 matrix.

Methods

origin :: v #

Origin point (0, 0, 0).

fromXYZ :: (Double, Double, Double) -> v #

Construct a new vector from components.

toXYZ :: v -> (Double, Double, Double) #

Deconstruct a vector into components.

zipWith :: (Double -> Double -> Double) -> v -> v -> v #

Zip two vectors elementwise.

(<+>) :: v -> v -> v #

Add two vectors.

(<->) :: v -> v -> v #

Subtract two vectors.

(><) :: v -> v -> v #

Cross product.

(.^) :: v -> Double -> v #

Scale a vector.

(.*) :: v -> v -> Double #

Dot product.

norm :: v -> Double #

Euclidean norm of a vector.

normalize :: v -> v #

Produce unit vector with the same direction as the original one.

distance :: v -> v -> Double #

Distance between two points.

invert :: v -> v #

Invert the direction of a vector.

fromRows :: (v, v, v) -> Matrix v #

Construct a new matrix from rows.

toRows :: Matrix v -> (v, v, v) #

Deconstruct a matrix into rows.

dotM :: v -> v -> Matrix v -> Double #

Generic vector dot product.

Multiply the transpose of the first vector by the given matrix, then multiply the result by the second vector.

                    [ a11  a12  a13 ]   [ v2x ]
                    [               ]   [     ]
[ v1x  v1y  v1z ] . [ a21  a22  a23 ] . [ v2y ] = s
                    [               ]   [     ]
                    [ a31  a32  a33 ]   [ v2z ]

mxv :: Matrix v -> v -> v #

Multiply a matrix and a vector.

[ a11  a12  a13 ]   [ v2x ]   [ rx ]
[               ]   [     ]   [    ]
[ a21  a22  a23 ] . [ v2y ] = [ ry ]
[               ]   [     ]   [    ]
[ a31  a32  a33 ]   [ v2z ]   [ rz ]

diag :: Double -> Matrix v #

Build a diagonal matrix from a number d.

[ d  0  0 ]
[         ]
[ 0  d  0 ]
[         ]
[ 0  0  d ]

vxv :: v -> v -> Matrix v #

Transpose a vector and multiply it by another vector, producing a matrix.

[ v1x ]                       [ r11  r12  r13 ]
[     ]                       [               ]
[ v1y ] . [ v2x  v2y  v2z ] = [ r21  r22  r23 ]
[     ]                       [               ]
[ v1z ]                       [ r31  r32  r33 ]

addM :: Matrix v -> Matrix v -> Matrix v #

Add two matrices.

Instances
Vec3 TVec3 # 
Instance details

Defined in Data.Vec3.Class

Associated Types

data Matrix TVec3 :: * #

Vec3 CVec3 # 
Instance details

Defined in Data.Vec3

Associated Types

data Matrix CVec3 :: * #

type TVec3 = (Double, Double, Double) #

Vec3 implementation with Unbox instance based on default Unbox instance for tuples of arrays, which wraps a vector of tuples as a tuple of vectors.

interface:  [v1 (x, y, z); v2 (x, y, z) ...], length = N
                 |  |  |       |  |  |
storage(x): [v1x-+  |  | ; v2x-+  |  |  ...], length = N
storage(y): [v1y----+  | ; v2y----+  |  ...], length = N
storage(z): [v1z-------+ ; v2z-------+  ...], length = N

You almost definitely want to use CVec3 instead as it has better performance.