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

@type vec3() :: {float(), float(), float()}
@type vec4() :: {float(), float(), float(), float()}

Functions

@spec add(vec4(), vec4()) :: vec4()

Adds corresponding components.

Link to this function

chebyshev_distance(arg1, arg2)

View Source
@spec chebyshev_distance(vec4(), vec4()) :: float()

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.

@spec create([float()]) :: vec4()

Creates a vector from the first four list entries, converting them to floats. Extra entries are ignored; fewer than four entries raise FunctionClauseError.

@spec create(float(), float(), float(), float()) :: vec4()

Creates a vector from four components, converting numeric inputs to floats.

@spec dot(vec4(), vec4()) :: float()

Returns the four-dimensional dot product.

@spec equal(vec4(), vec4()) :: boolean()

Tests exact numeric equality of all four components.

@spec equal(vec4(), vec4(), float()) :: boolean()

Tests whether each component differs by at most eps (inclusive).

@spec from_direction3(vec3()) :: vec4()

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}
@spec from_point3(vec3()) :: vec4()

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}
@spec length(vec4()) :: float()

Returns the Euclidean length, including the fourth component.

@spec length_manhattan(vec4()) :: float()

Returns the sum of the absolute values of all four components.

@spec length_squared(vec4()) :: float()

Returns the squared Euclidean length.

@spec lerp(vec4(), vec4(), float()) :: vec4()

Linearly interpolates all four components: (1 - alpha) * a + alpha * b. Use alpha from 0.0 through 1.0 to interpolate between the endpoints.

Link to this function

minkowski_distance(arg1, arg2, order)

View Source
@spec minkowski_distance(vec4(), vec4(), float()) :: float()

Returns the Minkowski distance using all four components. order should be at least 1.0; order zero raises ArithmeticError.

@spec multiply(vec4(), vec4()) :: vec4()

Multiplies corresponding components.

Link to this function

near(arg1, arg2, distance)

View Source
@spec near(vec4(), vec4(), float()) :: boolean()

Tests whether the Euclidean distance is strictly less than distance. Points exactly on the distance boundary return false.

@spec negate(vec4()) :: vec4()

Negates all four components.

@spec normalize(vec4()) :: vec4()

Returns a unit vector in the same four-dimensional direction. Raises ArithmeticError for the zero vector.

@spec p_norm(vec4(), float()) :: float()

Returns the Lp norm using all four components. order should be at least 1.0; order zero raises ArithmeticError.

@spec project(vec4(), vec4()) :: vec4()

Projects a onto b in four dimensions. Raises ArithmeticError when the target b is zero.

@spec scale(vec4(), float()) :: vec4()

Multiplies all four components by k, including the homogeneous coordinate.

@spec subtract(vec4(), vec4()) :: vec4()

Subtracts corresponding components of b from a.

Link to this function

weighted_sum(a, arg1, b, arg2)

View Source
@spec weighted_sum(float(), vec4(), float(), vec4()) :: vec4()

Returns a * v1 + b * v2, using all four components.