elm-explorations / linear-algebra / 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 : Basics.Float -> Basics.Float -> Basics.Float -> Basics.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 -> Basics.Float

Extract the x component of a vector.

getY : Vec4 -> Basics.Float

Extract the y component of a vector.

getZ : Vec4 -> Basics.Float

Extract the z component of a vector.

getW : Vec4 -> Basics.Float

Extract the w component of a vector.

setX : Basics.Float -> Vec4 -> Vec4

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

setY : Basics.Float -> Vec4 -> Vec4

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

setZ : Basics.Float -> Vec4 -> Vec4

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

setW : Basics.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

negate : Vec4 -> Vec4

Vector negation: -a

scale : Basics.Float -> Vec4 -> Vec4

Multiply the vector by a scalar: s * v

dot : Vec4 -> Vec4 -> Basics.Float

The dot product of a and b

normalize : Vec4 -> Vec4

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

direction : Vec4 -> Vec4 -> Vec4

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

length : Vec4 -> Basics.Float

The length of the given vector: |a|

lengthSquared : Vec4 -> Basics.Float

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

distance : Vec4 -> Vec4 -> Basics.Float

The distance between two vectors.

distanceSquared : Vec4 -> Vec4 -> Basics.Float

The square of the distance between two vectors.

Conversions

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

Convert a vector to a record.

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

Convert a record to a vector.