elm-explorations/linear-algebra/1.0.0

NOTE: the latest version is 1.0.3

Math.Vector4

A high performance linear algebra library using native JS arrays. Geared towards 3D graphics and use with Graphics.WebGL. All vectors are immutable.

Create

type Vec4

Four dimensional vector type

vec4 : Float -> Float -> Float -> Float -> Vec4

Creates a new 4-element vector with the given x, y, z, and w values.

Get and Set

The set functions create a new copy of the vector, updating a single field.

getX : Vec4 -> Float

Extract the x component of a vector.

getY : Vec4 -> Float

Extract the y component of a vector.

getZ : Vec4 -> Float

Extract the z component of a vector.

getW : Vec4 -> Float

Extract the w component of a vector.

setX : Float -> Vec4 -> Vec4

Update the x component of a vector, returning a new vector.

setY : Float -> Vec4 -> Vec4

Update the y component of a vector, returning a new vector.

setZ : Float -> Vec4 -> Vec4

Update the z component of a vector, returning a new vector.

setW : Float -> Vec4 -> Vec4

Update the w component of a vector, returning a new vector.

Operations

add : Vec4 -> Vec4 -> Vec4

Vector addition: a + b

sub : Vec4 -> Vec4 -> Vec4

Vector subtraction: a - b

Vector negation: -a

scale : Float -> Vec4 -> Vec4

Multiply the vector by a scalar: s * v

dot : Vec4 -> Vec4 -> Float

The dot product of a and b

A unit vector with the same direction as the given vector: a / |a|

The normalized direction from b to a: (a - b) / |a - b|

length : Vec4 -> Float

The length of the given vector: |a|

lengthSquared : Vec4 -> Float

The square of the length of the given vector: |a| * |a|

distance : Vec4 -> Vec4 -> Float

The distance between two vectors.

distanceSquared : Vec4 -> Vec4 -> Float

The square of the distance between two vectors.

Conversions

-> { x : Float
, y : Float
, z : Float
, w : Float
}

Convert a vector to a record.

{ x : Float
, y : Float
, z : Float
, w : Float
}
-> Vec4

Convert a record to a vector.