Module

Linear.V4

Package
purescript-linear
Repository
afcondon/purescript-linear

4-dimensional vectors.

This module provides the V4 type for 4D vector operations, commonly used for homogeneous coordinates in 3D graphics.

#V4 Source

data V4 a

A 4-dimensional vector.

Often used for homogeneous coordinates where (x, y, z, w) represents the 3D point (x/w, y/w, z/w).

origin = V4 0.0 0.0 0.0 1.0
direction = V4 1.0 0.0 0.0 0.0

Constructors

  • V4 a a a a

Instances

#vector Source

vector :: forall a. Semiring a => V3 a -> V4 a

Convert a 3D vector to homogeneous coordinates with w=0.

This represents a direction (not a point) in homogeneous coordinates.

vector (V3 1.0 0.0 0.0) = V4 1.0 0.0 0.0 0.0

#point Source

point :: forall a. Semiring a => V3 a -> V4 a

Convert a 3D point to homogeneous coordinates with w=1.

This represents a point (not a direction) in homogeneous coordinates.

point (V3 1.0 2.0 3.0) = V4 1.0 2.0 3.0 1.0

#normalizePoint Source

normalizePoint :: V4 Number -> V3 Number

Convert homogeneous coordinates back to 3D by dividing by w.

normalizePoint (V4 2.0 4.0 6.0 2.0) = V3 1.0 2.0 3.0

#ex Source

ex :: forall a. Semiring a => V4 a

Unit vector along the x-axis.

#ey Source

ey :: forall a. Semiring a => V4 a

Unit vector along the y-axis.

#ez Source

ez :: forall a. Semiring a => V4 a

Unit vector along the z-axis.

#ew Source

ew :: forall a. Semiring a => V4 a

Unit vector along the w-axis.

#getX Source

getX :: forall a. V4 a -> a

Get the x component of a V4.

#getY Source

getY :: forall a. V4 a -> a

Get the y component of a V4.

#getZ Source

getZ :: forall a. V4 a -> a

Get the z component of a V4.

#getW Source

getW :: forall a. V4 a -> a

Get the w component of a V4.