Physics

:= []

Physics module - friendly 3D projective geometric algebra primitives.

This module uses compact grade-specific PGA storage. The public API stays geometric, but each object stores coefficients for its PGA subspace rather than plain graphics vectors.

point : F32, F32, F32 -> Point

Construct a finite point from x, y, and z coordinates.

point_xy : F32, F32 -> Point

Construct a finite point on the z=0 plane.

origin : Point

The finite point at the coordinate origin.

vector : F32, F32, F32 -> Vector

Construct a free vector from x, y, and z components.

zero : Vector

The zero vector.

coords : Point -> Coords

Return normalized x, y, and z coordinates for a point.

components : Vector -> Coords

Return x, y, and z components for a free vector.

xy : Point -> Vec2

Return the x/y components of a point for 2D drawing boundaries.

point_coeffs : Point -> PointCoeffs

Return a read-only point coefficient record.

vector_coeffs : Vector -> VectorCoeffs

Return a read-only vector coefficient record.

plane_coeffs : Plane -> PlaneCoeffs

Return a read-only plane coefficient record.

line_coeffs : Line -> LineCoeffs

Return a read-only line coefficient record.

motor_coeffs : Motor -> MotorCoeffs

Return a read-only motor coefficient record.

add : Point, Vector -> Point

Translate a point by a free vector.

sub : Point, Point -> Vector

Return the free vector from the second point to the first point.

add_vec : Vector, Vector -> Vector

Add two free vectors.

sub_vec : Vector, Vector -> Vector

Subtract the second free vector from the first.

scale : Vector, F32 -> Vector

Scale a free vector by a scalar amount.

dot : Vector, Vector -> F32

Compute the Euclidean dot product of two free vectors.

cross : Vector, Vector -> Vector

Compute the Euclidean cross product of two free vectors.

length_squared : Vector -> F32

Compute the squared Euclidean length of a free vector.

length : Vector -> F32

Compute the Euclidean length of a free vector.

normalize : Vector -> Vector

Return a unit-length vector, or zero for a zero-length input.

reflect : Vector, Vector -> Vector

Reflect a vector around a surface normal.

distance : Point, Point -> F32

Compute the Euclidean distance between two finite points.

plane : Vector, F32 -> Plane

Construct a normalized plane from a normal and signed distance to origin.

plane_from_point_normal : Point, Vector -> Plane

Construct a plane through a point with the given normal direction.

signed_distance : Plane, Point -> F32

Compute the signed Euclidean distance from a normalized plane to a point.

line_from_points : Point, Point -> Line

Construct a PGA line passing through two finite points.

translation : Vector -> Motor

Construct a translation motor from a free offset vector.

translation_vector : Motor -> Vector

Extract the translation offset represented by a translation motor.

apply_motor_point : Motor, Point -> Point

Apply a translation motor to a finite point.

body : Point, Vector -> Body

Construct a simple particle body.

apply_acceleration : Body, Vector, F32 -> Body

Integrate acceleration into a body's velocity over a time step.

integrate_body : Body, F32 -> Body

Integrate velocity into a body's position over a time step.

clamp_y : Vector, F32, F32 -> Vector

Clamp only the y component of a free vector.

Point

:= {
    e032 : F32,
    e013 : F32,
    e021 : F32,
    e123 : F32,
}

A finite 3D PGA point stored as compact grade-3 homogeneous coefficients.

Vector

:= {
    e032 : F32,
    e013 : F32,
    e021 : F32,
}

A free 3D direction or translation stored as the ideal part of a point.

Plane

:= {
    e0 : F32,
    e1 : F32,
    e2 : F32,
    e3 : F32,
}

A 3D PGA plane stored as grade-1 coefficients.

Line

:= {
    e01 : F32,
    e02 : F32,
    e03 : F32,
    e23 : F32,
    e31 : F32,
    e12 : F32,
}

A 3D PGA line stored as six grade-2 Plucker-style coefficients.

Motor

:= {
    s : F32,
    e23 : F32,
    e31 : F32,
    e12 : F32,
    e01 : F32,
    e02 : F32,
    e03 : F32,
    e0123 : F32,
}

A 3D PGA motor stored as compact even-subalgebra coefficients.

Body : {
    position : Point,
    velocity : Vector,
}

A simple particle body with a PGA point position and vector velocity.

Coords : {
    x : F32,
    y : F32,
    z : F32,
}

Plain coordinate view returned by accessors.