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

Data.Vec3

Synopsis

# Documentation

class Vec3 v whereSource

Three-dimensional vector, with an associated matrix type.

Associated Types

data Matrix v Source

Associated type for 3×3 matrix.

Methods

origin :: vSource

Origin point `(0, 0, 0)`.

fromXYZ :: (Double, Double, Double) -> vSource

Construct a new vector from components.

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

Deconstruct a vector into components.

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

Zip two vectors elementwise.

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

(<->) :: v -> v -> vSource

Subtract two vectors.

(><) :: v -> v -> vSource

Cross product.

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

Scale a vector.

(.*) :: v -> v -> DoubleSource

Dot product.

norm :: v -> DoubleSource

Euclidean norm of a vector.

normalize :: v -> vSource

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

distance :: v -> v -> DoubleSource

Distance between two points.

invert :: v -> vSource

Invert the direction of a vector.

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

Construct a new matrix from rows.

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

Deconstruct a matrix into rows.

dotM :: v -> v -> Matrix v -> DoubleSource

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 -> vSource

Multiply a matrix and a vector.

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

Build a diagonal matrix from a number `d`.

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

vxv :: v -> v -> Matrix vSource

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 vSource

Instances

 Vec3 SVec3 Vec3 TUVec3 Vec3 UVec3

data UVec3 Source

`Vec3` implementation with `Unbox` instance based on a single contiguous array storage scheme, suitable for use with Data.Vector.Unboxed.

`Unbox` instance provides the required index transformations.

``` interface: [d1 x   y   z  ; d2 x   y   z  ...], length = N = M / 3
|   |   |       |   |   |
storage:   [  d1x d2y d2z ;   d2x d2y d2z ...], length = M
```

Thanks to dense packing scheme the performance of this implementation should generally be on par with `Storable`-based `SVec3`.

Constructors

 UVec3 !Double !Double !Double

Instances

 Eq UVec3 Show UVec3 Unbox UVec3 Vec3 UVec3 Vector Vector UVec3 MVector MVector UVec3

data SVec3 Source

`Vec3` implementation with `Storable` instance, suitable for use with Data.Vector.Storable.

Constructors

 SVec3 !CDouble !CDouble !CDouble

Instances

 Eq SVec3 Show SVec3 Storable SVec3 Vec3 SVec3

newtype TUVec3 Source

`Vec3` implementation with `Unbox` instance based on tuples, suitable for use with Data.Vector.Unboxed.

This represents 3-vector as a triple of doubles, using the default Unbox instance for tuples as provided by Data.Vector.Unboxed, which wraps a vector of tuples as a tuple of vectors.

``` interface:  [d1 (x, y, z); d2 (x, y, z) ...], length = N
|  |  |       |  |  |
storage(x): [d1x-+  |  | ; d2x-+  |  |  ...], length = N
storage(y): [d1y----+  | ; d2y----+  |  ...], length = N
storage(z): [d1z-------+ ; d2z-------+  ...], length = N
```

Constructors

 TUVec3 (Double, Double, Double)

Instances

 Eq TUVec3 Show TUVec3 Unbox TUVec3 Vec3 TUVec3 Vector Vector TUVec3 MVector MVector TUVec3 Vector Vector (Matrix TUVec3) MVector MVector (Matrix TUVec3) Eq (Matrix TUVec3) Show (Matrix TUVec3) Unbox (Matrix TUVec3)