Three-dimensional Conformal Geometric Algebra (CGA).
This module implements CGA for Euclidean 3-space using the signature:
{1, 1, 1, 1, -1}with basis:
e1, e2, e3, ep, emThe Euclidean basis vectors represent ordinary 3D coordinates. The additional conformal basis vectors are combined into the null vectors:
e0 = (ep + em) / 2
einf = em - epPoints are embedded into conformal space using:
P(x,y,z) =
e0
+ x*e1
+ y*e2
+ z*e3
+ 1/2(x²+y²+z²)einfGeometric objects such as lines, planes, and spheres are represented as multivectors using outer products.
Examples
iex> p = Galixir.Algebras.CGA3.point(1, 2, 3)
iex> Galixir.Algebras.CGA3.point_coordinates(p)
{1.0, 2.0, 3.0}
Summary
Functions
Adds two multivectors component-wise.
Checks whether a multivector is a blade.
Returns the mapping between blade names and storage indices.
Returns the canonical sign of a multivector.
Returns the coefficient of a basis blade.
Tests whether a conformal point lies on an object.
Returns the dimension of the algebra.
Computes the scalar product of two multivectors.
Computes the dual of a multivector.
Returns the conformal origin vector.
Returns the infinity vector.
Computes the geometric product of two multivectors.
Extracts the grade-g component of a multivector.
Returns the grades present in a multivector.
Computes the inner product of two multivectors.
Computes the inverse of a multivector.
Computes the join of two CGA objects.
Computes the left contraction of two multivectors.
Creates a line through two conformal points.
Returns the maximum absolute coefficient of a multivector.
Computes the meet (intersection) of two CGA objects.
Returns the norm of a multivector.
Normalizes a multivector.
Returns the scalar identity element.
Returns the conformal representation of the Euclidean origin.
Creates a plane through three conformal points.
Embeds a Euclidean point into conformal space.
Extracts Euclidean coordinates from a conformal point.
Returns the CGA3 pseudoscalar
Applies the reverse operation to a multivector.
Computes the right contraction of two multivectors.
Creates a rotor from a normalized bivector and angle.
Computes the rotor that maps one frame to another.
Checks whether a multivector contains only a scalar component.
Returns the scalar coefficient of a multivector.
Computes the scalar product of two multivectors.
Returns the metric signature of the algebra.
Returns the number of coefficients stored by the algebra.
Creates a sphere from a center point and radius.
Creates a sphere through four conformal points.
Returns the squared norm of a multivector.
Subtracts two multivectors component-wise.
Returns the multiplication table for the algebra.
Formats a multivector using standard geometric algebra notation.
Applies a motor transformation to a CGA object.
Creates a translator motor from a Euclidean vector.
Creates a translator motor.
Computes the inverse dual operation.
Creates a Euclidean vector.
Computes the outer product (wedge product) of two multivectors.
Computes the outer product of a list of multivectors.
Returns the zero multivector.
Checks whether all coefficients of a multivector are zero.
Functions
Adds two multivectors component-wise.
Examples
iex> a = Galixir.Algebras.CGA3.new(scalar: 2)
iex> b = Galixir.Algebras.CGA3.new(scalar: 3)
iex> Galixir.Algebras.CGA3.add(a, b)
Galixir.Algebras.CGA3.new(scalar: 5)
Checks whether a multivector is a blade.
A blade is a multivector containing components from at most one grade.
Scalars are considered blades.
Examples
iex> Galixir.Algebras.CGA3.blade?(Galixir.Algebras.CGA3.new(e1: 2))
true
iex> Galixir.Algebras.CGA3.blade?(Galixir.Algebras.CGA3.new(e12: 1))
true
iex> Galixir.Algebras.CGA3.blade?(Galixir.Algebras.CGA3.new(e1: 1, e2: 1))
true
iex> Galixir.Algebras.CGA3.blade?(Galixir.Algebras.CGA3.new(scalar: 2, e1: 2))
false
iex> Galixir.Algebras.CGA3.blade?(Galixir.Algebras.CGA3.new(e2: 2, e12: 2))
false
Returns the mapping between blade names and storage indices.
Blade coefficients are stored in a fixed-size tuple. This map translates canonical blade names into their corresponding tuple index.
Example
iex> blade_indices()[:e1]
1
Returns the canonical sign of a multivector.
The canonical sign is determined by the first non-zero coefficient in storage order.
Returns:
1if the first non-zero coefficient is positive-1if the first non-zero coefficient is negative0if all coefficients are zero
Examples
iex> canonical_sign(new(e1: 2))
1
iex> canonical_sign(new(e1: -2))
-1
iex> canonical_sign(new())
0
Returns the coefficient of a basis blade.
The requested blade can be given in canonical form or as any registered blade alias. Aliases are automatically converted to the canonical blade and the appropriate sign is applied.
## Examples
iex> coefficient( ...> new(e1: 3), ...> :e1 ...> ) 3.0
Tests whether a conformal point lies on an object.
Returns the dimension of the algebra.
This is the number of basis vectors defined by the signature.
Computes the scalar product of two multivectors.
Returns the scalar part of their geometric product.
Computes the dual of a multivector.
The dual maps each basis blade to its complementary blade with the appropriate orientation sign. The complement is determined by the full pseudoscalar of the algebra.
The operation is linear and applies independently to every coefficient.
Examples
iex> dual(new(e1: 1)) |> inspect
new(e23pm: 1.0) |> inspect
Returns the conformal origin vector.
Defined as:
e0 = (ep + em) / 2
Returns the infinity vector.
The infinity vector represents the point at infinity:
einf = em - ep
Computes the geometric product of two multivectors.
The geometric product is the fundamental multiplication operation of geometric algebra. It combines the outer product and metric-dependent inner product into a single associative operation.
The result depends on the algebra's metric signature.
Examples
iex> Galixir.Algebras.CGA3.gp(
...> Galixir.Algebras.CGA3.new(e1: 1),
...> Galixir.Algebras.CGA3.new(e1: 1)
...> )
Galixir.Algebras.CGA3.new(scalar: 1)
Extracts the grade-g component of a multivector.
All coefficients whose basis blades are not of grade g are set to zero.
Raises ArgumentError if g is outside the range 0..dimension().
Examples
iex> Galixir.Algebras.CGA3.grade(
...> Galixir.Algebras.CGA3.new(scalar: 1, e1: 2),
...> 1
...> )
Galixir.Algebras.CGA3.new(e1: 2)
iex> Galixir.Algebras.CGA3.grade(
...> Galixir.Algebras.CGA3.new(scalar: 1, e1: 2),
...> 0
...> )
Galixir.Algebras.CGA3.new(scalar: 1)
Returns the grades present in a multivector.
The returned list contains every grade with at least one non-zero coefficient, ordered from lowest to highest.
Examples
iex> Galixir.Algebras.CGA3.grades(
...> Galixir.Algebras.CGA3.new(scalar: 1)
...> )
[0]
iex> Galixir.Algebras.CGA3.grades(
...> Galixir.Algebras.CGA3.new(e1: 2)
...> )
[1]
iex> Galixir.Algebras.CGA3.grades(
...> Galixir.Algebras.CGA3.new(scalar: 1, e1: 2)
...> )
[0, 1]
iex> Galixir.Algebras.CGA3.grades(
...> Galixir.Algebras.CGA3.new()
...> )
[]
Computes the inner product of two multivectors.
The operation is generated from the geometric product and retains only terms satisfying the grade selection rule.
Example
iex> Galixir.Algebras.CGA3.inner(
...> Galixir.Algebras.CGA3.new(e1: 2),
...> Galixir.Algebras.CGA3.new(e1: 3)
...> )
Computes the inverse of a multivector.
The inverse is computed using the reverse:
inverse(a) = reverse(a) / scalar_part(a * reverse(a))
This formula is valid when a * reverse(a) is a non-zero scalar.
Raises ArgumentError if the multivector is not invertible by this formula.
## Examples
iex> Galixir.Algebras.CGA3.inverse(
...> Galixir.Algebras.CGA3.new(e1: 2)
...> )|> inspect
Galixir.Algebras.CGA3.new(e1: 0.5) |> inspect
Computes the join of two CGA objects.
The join is the outer product:
join(a,b) = a ∧ b
Computes the left contraction of two multivectors.
The operation is generated from the geometric product and retains only terms satisfying the grade selection rule.
Example
iex> Galixir.Algebras.CGA3.left_contraction(
...> Galixir.Algebras.CGA3.new(e1: 2),
...> Galixir.Algebras.CGA3.new(e1: 3)
...> )
Creates a line through two conformal points.
The line is represented by:
L = a ∧ b ∧ einf
Returns the maximum absolute coefficient of a multivector.
Accepts either a multivector struct or the internal coefficient tuple.
Example
iex> max_abs_component(new(e1: 2, scalar: 5))
5.0
iex> max_abs_component(new(e1: 5, scalar: 2))
5.0
Computes the meet (intersection) of two CGA objects.
The meet is implemented through duality:
meet(a,b) = dual(dual(a) ∧ dual(b))
Returns the norm of a multivector.
The norm is the square root of the absolute squared norm.
Example
iex> a = Galixir.Algebras.CGA3.new(scalar: 3)
iex> Galixir.Algebras.CGA3.norm(a)
3.0
Normalizes a multivector.
The result has unit norm while preserving the direction of the multivector.
Raises ArgumentError when attempting to normalize a null
multivector.
Example
iex> a = Galixir.Algebras.CGA3.new(scalar: 2)
iex> Galixir.Algebras.CGA3.norm(Galixir.Algebras.CGA3.normalize(a))
1.0
Returns the scalar identity element.
Returns the conformal representation of the Euclidean origin.
Creates a plane through three conformal points.
The plane is represented by:
Π = a ∧ b ∧ c ∧ einf
Embeds a Euclidean point into conformal space.
Uses the standard CGA point embedding:
P = e0 + x*e1 + y*e2 + z*e3
+ 1/2(x²+y²+z²)einf
Extracts Euclidean coordinates from a conformal point.
Returns:
{x, y, z}
Returns the CGA3 pseudoscalar:
e1 ∧ e2 ∧ e3 ∧ ep ∧ em
Applies the reverse operation to a multivector.
Reverse (also called reversion) changes the sign of basis blades according to their grade:
grade 0: +
grade 1: +
grade 2: -
grade 3: -
grade 4: +
...For a blade with grade r, the sign is:
(-1)^(r(r-1)/2)Examples
iex> Galixir.Algebras.CGA3.reverse(Galixir.Algebras.CGA3.new(e1: 2)) |> inspect
Galixir.Algebras.CGA3.new(e1: 2)|> inspect
iex> Galixir.Algebras.CGA3.reverse(Galixir.Algebras.CGA3.new(e12: 2))|> inspect
Galixir.Algebras.CGA3.new(e12: -2)|> inspect
iex> Galixir.Algebras.CGA3.reverse(Galixir.Algebras.CGA3.new(scalar: 3))|> inspect
Galixir.Algebras.CGA3.new(scalar: 3)|> inspect
Computes the right contraction of two multivectors.
The operation is generated from the geometric product and retains only terms satisfying the grade selection rule.
Example
iex> Galixir.Algebras.CGA3.right_contraction(
...> Galixir.Algebras.CGA3.new(e1: 2),
...> Galixir.Algebras.CGA3.new(e1: 3)
...> )
Creates a rotor from a normalized bivector and angle.
The angle is measured in radians.
Computes the rotor that maps one frame to another.
The function constructs blades from the source and target frames and computes the transformation rotor:
R = normalize(1 + T * S⁻¹)
where S is the source frame blade and T is the target frame blade.
The resulting rotor can be applied to multivectors to rotate the source frame into the target frame.
Checks whether a multivector contains only a scalar component.
Components with an absolute value smaller than eps are considered
zero.
Examples
iex> Galixir.Algebras.CGA3.scalar?(Galixir.Algebras.CGA3.new(scalar: 3))
true
iex> Galixir.Algebras.CGA3.scalar?(Galixir.Algebras.CGA3.new(e1: 3))
false
iex> Galixir.Algebras.CGA3.scalar?(Galixir.Algebras.CGA3.new())
true
Returns the scalar coefficient of a multivector.
This is equivalent to retrieving the coefficient of the scalar blade.
Examples
iex> scalar_part(new(scalar: 5.0, e1: 2.0))
5.0
Computes the scalar product of two multivectors.
The scalar product is the grade-0 component of the geometric product:
<a b>₀The result depends on the metric signature of the algebra. In particular, basis vectors with negative or null squares affect the result.
Examples
iex> Galixir.Algebras.CGA3.scalar_product(
...> Galixir.Algebras.CGA3.new(e1: 2),
...> Galixir.Algebras.CGA3.new(e1: 3)
...> )
6.0
Returns the metric signature of the algebra.
Example:
{1, 1, 1, 0}represents a projective geometric algebra with three Euclidean basis vectors and one null basis vector.
Returns the number of coefficients stored by the algebra.
A dimension n algebra contains 2^n basis blades.
Creates a sphere from a center point and radius.
The radius is encoded using the infinity vector term.
Creates a sphere through four conformal points.
The resulting multivector represents the unique sphere containing the four points.
Returns the squared norm of a multivector.
The squared norm is computed as:
scalar_part(a * reverse(a))The result may be negative for algebras with indefinite metrics.
Example
iex> a = Galixir.Algebras.CGA3.new(scalar: 3)
iex> Galixir.Algebras.CGA3.squared_norm(a)
9.0
Subtracts two multivectors component-wise.
Examples
iex> a = Galixir.Algebras.CGA3.new(scalar: 5)
iex> b = Galixir.Algebras.CGA3.new(scalar: 2)
iex> Galixir.Algebras.CGA3.sub(a, b)
Galixir.Algebras.CGA3.new(scalar: 3)
Returns the multiplication table for the algebra.
The table contains precomputed geometric products between basis blades.
Each entry maps {left_blade, right_blade} to {coefficient, result_blade}.
The blades are represented internally as bitmasks.
Example
iex> table() |> Map.has_key?({1, 1})
true
Formats a multivector using standard geometric algebra notation.
Zero coefficients are omitted. Coefficients of 1 and -1 are elided for
non-scalar basis blades.
Examples
iex> inspect(Galixir.Algebras.CGA3.new())
"0"
iex> inspect(Galixir.Algebras.CGA3.new(scalar: 2))
"2.0"
iex> inspect(Galixir.Algebras.CGA3.new(e1: 1))
"e1"
iex> inspect(Galixir.Algebras.CGA3.new(scalar: 1, e1: 2))
"1.0 + 2.0e1"
Applies a motor transformation to a CGA object.
Uses the sandwich product:
M X reverse(M)
Creates a translator motor from a Euclidean vector.
Creates a translator motor.
The motor translates objects by the Euclidean displacement:
{x,y,z}
Computes the inverse dual operation.
undual/1 reverses the blade complement operation performed by
dual/1.
For non-degenerate Euclidean algebras this corresponds to applying the dual operation twice with the appropriate pseudoscalar factor. In degenerate algebras the result depends on the implemented dual convention.
Examples
iex> undual(dual(new(e1: 2)))
new(e1: 2)
Creates a Euclidean vector.
This creates only the Euclidean part:
x*e1 + y*e2 + z*e3Use point/3 to create a conformal point.
Computes the outer product (wedge product) of two multivectors.
The wedge product combines blades by joining their basis vectors. It is antisymmetric:
a ∧ b = -(b ∧ a)and vanishes when the operands share a basis vector.
Examples
iex> Galixir.Algebras.CGA3.wedge(
...> Galixir.Algebras.CGA3.new(e1: 1),
...> Galixir.Algebras.CGA3.new(e2: 1)
...> )
Galixir.Algebras.CGA3.new(e12: 1)
iex> Galixir.Algebras.CGA3.wedge(
...> Galixir.Algebras.CGA3.new(e2: 1),
...> Galixir.Algebras.CGA3.new(e1: 1)
...> )
Galixir.Algebras.CGA3.new(e12: -1)
iex> Galixir.Algebras.CGA3.wedge(
...> Galixir.Algebras.CGA3.new(e1: 1),
...> Galixir.Algebras.CGA3.new(e1: 1)
...> )
Galixir.Algebras.CGA3.new()
Computes the outer product of a list of multivectors.
The vectors are combined from left to right using the wedge product.
The result is a blade representing the subspace spanned by all input multivectors.
Returns the zero multivector.
Checks whether all coefficients of a multivector are zero.
Examples
iex> Galixir.Algebras.CGA3.zero?(Galixir.Algebras.CGA3.new())
true
iex> Galixir.Algebras.CGA3.zero?(Galixir.Algebras.CGA3.new(e1: 1))
false