nphollon / geo3d / Vector

Three-dimensional vector type.

Building


type alias Vector =
{ x : Basics.Float
, y : Basics.Float
, z : Basics.Float 
}

Vector is just a type alias for a record.

vector : Basics.Float -> Basics.Float -> Basics.Float -> Vector

Construct a vector from x, y, and z coordinates.

zero : Vector

The zero vector. zero == vector 0 0 0

identity : Vector

Alias for zero.

xAxis : Vector

Normal vector along the x axis.

xAxis == vector 1 0 0

yAxis : Vector

Normal vector along the y axis.

yAxis == vector 0 1 0

zAxis : Vector

Normal vector along the z axis.

zAxis == vector 0 0 1

Math

getX : Vector -> Basics.Float

Get the x component of a vector.

getX (vector 1 2 3) == 1

getY : Vector -> Basics.Float

Get the y component of a vector.

getY (vector 1 2 3) == 2

getZ : Vector -> Basics.Float

Get the z component of a vector.

getZ (vector 1 2 3) == 3

equal : Vector -> Vector -> Basics.Bool

Returns true when two vectors are about equal (within 10^-5).

add : Vector -> Vector -> Vector

Add two vectors.

sub : Vector -> Vector -> Vector

Subtract two vectors.

negate : Vector -> Vector

Negate a vector.

scale : Basics.Float -> Vector -> Vector

Multiply a vector by a number.

dot : Vector -> Vector -> Basics.Float

Compute the dot product of two vectors.

cross : Vector -> Vector -> Vector

Compute the cross product of two vectors.

normalize : Vector -> Maybe Vector

Return the unit vector that points in the same direction as the given vector. Return Nothing if given the zero vector.

normalize (vector 0 3 0) == Just (vector 0 1 0)
normalize (vector 0 0 0) == Nothing
normalize (vector 1 1 1) == Just (scale (1/sqrt 3) (vector 1 1 1))

length : Vector -> Basics.Float

Length of a vector. Always greater than or equal to zero.

lengthSquared : Vector -> Basics.Float

Square of the length of a vector.

direction : Vector -> Vector -> Maybe Vector

Return the unit vector that points from the second vector to the first vector. Return Nothing if the vectors are the same.

direction (vector 1 1 0) (vector -1 1 0) == Just (vector 1 0 0)
direction a b == normalize (a `sub` b)

distance : Vector -> Vector -> Basics.Float

Distance from one vector to another. Always greater than or equal to zero.

direction (vector 1 1 0) (vector -1 1 0) == 2
direction a b == length (a `sub` b)

distanceSquared : Vector -> Vector -> Basics.Float

Square of the distance between two vectors.

Interop

fromTuple : ( Basics.Float, Basics.Float, Basics.Float ) -> Vector

Convert a 3-tuple to a vector.

fromTuple (1, 2, 3) == vector 1 2 3

toTuple : Vector -> ( Basics.Float, Basics.Float, Basics.Float )

Convert a vector to a 3-tuple.

toTuple (vector 1 2 3) == (1, 2, 3)

encode : Vector -> Json.Encode.Value

Convert a vector into a Json Value.

decode : Json.Decode.Decoder Vector

A Json Decoder for vectors encoded with encode.

fromVec3 : Math.Vector3.Vec3 -> Vector

Convert from an elm-linear-algebra Vec3

toVec3 : Vector -> Math.Vector3.Vec3

Convert to an elm-linear-algebra Vec3