justgook/alt-linear-algebra/2.0.0

AltMath.Vector3

Create

type alias Vec3 =
{ x : Float
, y : Float
, z : Float
}

Three dimensional vector type

vec3 : Float -> Float -> Float -> Vec3

Creates a new 3-element vector with the given values.

i : Vec3

The unit vector î which points in the x direction: vec3 1 0 0

j : Vec3

The unit vector ĵ which points in the y direction: vec3 0 1 0

k : Vec3

The unit vector k̂ which points in the z direction: vec3 0 0 1

Get and Set

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

getX : Vec3 -> Float

Extract the x component of a vector.

getY : Vec3 -> Float

Extract the y component of a vector.

getZ : Vec3 -> Float

Extract the z component of a vector.

setX : Float -> Vec3 -> Vec3

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

setY : Float -> Vec3 -> Vec3

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

setZ : Float -> Vec3 -> Vec3

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

Operations

add : Vec3 -> Vec3 -> Vec3

Vector addition: a + b

sub : Vec3 -> Vec3 -> Vec3

Vector subtraction: a - b

negate : Vec3 -> Vec3

Vector negation: -a

scale : Float -> Vec3 -> Vec3

Multiply the vector by a scalar: s * v

dot : Vec3 -> Vec3 -> Float

The dot product of a and b

cross : Vec3 -> Vec3 -> Vec3

The cross product of a and b

normalize : Vec3 -> Vec3

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

direction : Vec3 -> Vec3 -> Vec3

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

length : Vec3 -> Float

The length of the given vector: |a|

lengthSquared : Vec3 -> Float

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

distance : Vec3 -> Vec3 -> Float

The distance between two vectors.

distanceSquared : Vec3 -> Vec3 -> Float

The square of the distance between two vectors.

Conversions

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

Convert a vector to a record.

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

Convert a record to a vector.