Physics

3D projective geometric algebra: points, lines, planes, and the motors that move them.

Reach for Math first. Its Vec2 and Rect are what every drawing call takes, and 2D positions, velocities, and axis-aligned boxes belong there. This module is for the problems that algebra cannot state: composing a rotation with a translation as one object, intersecting a line with a plane, or projecting one onto the other, in three dimensions and without special cases for parallel or coincident arguments.

Each object stores the coefficients of its own PGA subspace rather than plain graphics vectors, so the storage is compact and grade-specific. The public API stays geometric: construct points, lines and planes, and combine them with joins, meets, and motors.

These types live in the companion roc-ray-types package and are re-exported here, so a value passes between the two spellings freely and a library can depend on the package without depending on this platform.

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.

vector_xy_components : Vector -> Vec2

Return the x/y components of a vector 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 : Point

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

Vector : Vector

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

Plane : Plane

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

Line : Line

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

Motor : Motor

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

Body : Body

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

Coords : Coords

Plain coordinate view returned by accessors.

PointCoeffs : PointCoeffs

Read-only coefficient view for a point.

VectorCoeffs : VectorCoeffs

Read-only coefficient view for a vector.

PlaneCoeffs : PlaneCoeffs

Read-only coefficient view for a plane.

LineCoeffs : LineCoeffs

Read-only coefficient view for a line.

MotorCoeffs : MotorCoeffs

Read-only coefficient view for a motor.