View Source Graphmath.Vec4 (graphmath v3.0.0)
Four-dimensional vectors stored as {x, y, z, w} tuples of floats.
Arithmetic, lengths, normalization, and comparisons use all four components. Integer and mixed numeric inputs are accepted and arithmetic results are floats. The float-specialized clauses expose types to the VM for arithmetic optimization.
For homogeneous 3D coordinates, from_point3/1 sets w = 1.0 and
from_direction3/1 sets w = 0.0. Thus affine translation moves points
and leaves directions unchanged. Use Graphmath.Mat44.apply_left/2 for
the library's row-vector graphics convention; Graphmath.Mat44.apply/2
computes the column-vector product instead.
normalize/1 computes a unit vector in four dimensions. It does not divide
by the homogeneous coordinate to recover a Cartesian point.
Summary
Functions
Adds corresponding components.
Returns the largest absolute difference between corresponding components.
Returns the zero vector {0.0, 0.0, 0.0, 0.0}.
Creates a vector from the first four list entries, converting them to floats.
Extra entries are ignored; fewer than four entries raise FunctionClauseError.
Creates a vector from four components, converting numeric inputs to floats.
Returns the four-dimensional dot product.
Tests exact numeric equality of all four components.
Tests whether each component differs by at most eps (inclusive).
Embeds a 3D direction as {x, y, z, 0.0}, converting entries to floats.
Embeds a 3D point as {x, y, z, 1.0}, converting entries to floats.
Returns the Euclidean length, including the fourth component.
Returns the sum of the absolute values of all four components.
Returns the squared Euclidean length.
Linearly interpolates all four components: (1 - alpha) * a + alpha * b.
Use alpha from 0.0 through 1.0 to interpolate between the endpoints.
Returns the Minkowski distance using all four components.
order should be at least 1.0; order zero raises ArithmeticError.
Multiplies corresponding components.
Tests whether the Euclidean distance is strictly less than distance.
Points exactly on the distance boundary return false.
Negates all four components.
Returns a unit vector in the same four-dimensional direction.
Raises ArithmeticError for the zero vector.
Returns the Lp norm using all four components.
order should be at least 1.0; order zero raises ArithmeticError.
Projects a onto b in four dimensions.
Raises ArithmeticError when the target b is zero.
Multiplies all four components by k, including the homogeneous coordinate.
Subtracts corresponding components of b from a.
Returns a * v1 + b * v2, using all four components.
Types
Functions
Adds corresponding components.
Returns the largest absolute difference between corresponding components.
@spec create() :: vec4()
Returns the zero vector {0.0, 0.0, 0.0, 0.0}.
Use from_point3({0.0, 0.0, 0.0}) for the homogeneous 3D origin.
Creates a vector from the first four list entries, converting them to floats.
Extra entries are ignored; fewer than four entries raise FunctionClauseError.
Creates a vector from four components, converting numeric inputs to floats.
Returns the four-dimensional dot product.
Tests exact numeric equality of all four components.
Tests whether each component differs by at most eps (inclusive).
Embeds a 3D direction as {x, y, z, 0.0}, converting entries to floats.
Examples
iex> Graphmath.Vec4.from_direction3({2, -3, 4})
{2.0, -3.0, 4.0, 0.0}
Embeds a 3D point as {x, y, z, 1.0}, converting entries to floats.
Examples
iex> Graphmath.Vec4.from_point3({2, -3, 4})
{2.0, -3.0, 4.0, 1.0}
Returns the Euclidean length, including the fourth component.
Returns the sum of the absolute values of all four components.
Returns the squared Euclidean length.
Linearly interpolates all four components: (1 - alpha) * a + alpha * b.
Use alpha from 0.0 through 1.0 to interpolate between the endpoints.
Returns the Minkowski distance using all four components.
order should be at least 1.0; order zero raises ArithmeticError.
Multiplies corresponding components.
Tests whether the Euclidean distance is strictly less than distance.
Points exactly on the distance boundary return false.
Negates all four components.
Returns a unit vector in the same four-dimensional direction.
Raises ArithmeticError for the zero vector.
Returns the Lp norm using all four components.
order should be at least 1.0; order zero raises ArithmeticError.
Projects a onto b in four dimensions.
Raises ArithmeticError when the target b is zero.
Multiplies all four components by k, including the homogeneous coordinate.
Subtracts corresponding components of b from a.
Returns a * v1 + b * v2, using all four components.