Skip to content

Latest commit

 

History

History
109 lines (78 loc) · 2.94 KB

File metadata and controls

109 lines (78 loc) · 2.94 KB

Geometry Module

Quaternions, rotations, transforms, and geometric primitives.

Quaternion(T)

Unit quaternion for 3D rotations. Aliases: Quaternionf (f32), Quaterniond (f64).

Construction

Quaternionf.identity()                      // No rotation
Quaternionf.init(w, x, y, z)               // Direct
Quaternionf.fromAxisAngle(axis, angle)      // From axis + angle
Quaternionf.fromRotationMatrix(R)           // From 3x3 rotation matrix

Operations

q.mul(other)                // Compose rotations
q.conjugate()               // Conjugate (q*)
q.inverse()                 // Inverse (q⁻¹)
q.norm()                    // Quaternion norm
q.normalized()              // Unit quaternion
q.rotate(vector)            // Rotate a 3D vector
q.toRotationMatrix()        // Convert to 3x3 matrix
q.slerp(other, t)           // Spherical linear interpolation (t ∈ [0,1])

Transform(T)

Rigid body transform (rotation + translation) in 3D.

Transform(f32).identity()
Transform(f32).init(rotation_matrix, translation_vector)
Transform(f32).fromQuaternion(q, translation_vector)

t.transformPoint(point)     // Apply rotation + translation
t.transformVector(vec)      // Apply rotation only
t.mul(other)                // Compose transforms
t.inverse()                 // Inverse transform
t.toMatrix()                // To 4x4 homogeneous matrix

Rotation Types

AngleAxis(T)

Axis-angle representation.

AngleAxis(f32).init(angle, axis)
aa.toRotationMatrix()       // Convert to 3x3 matrix
aa.toQuaternion()           // Convert to quaternion

Rotation2D(T)

2D rotation by angle.

Rotation2D(f32).init(angle)
r.toMatrix()                // 2x2 rotation matrix
r.rotate(vector)            // Rotate 2D vector

Euler Angles

const R = Zigen.eulerToRotationMatrix(f64, .X, .Y, .Z, angles);

Transform Modes

Type Description
Isometry(T) Rigid body (rotation + translation)
Affine(T) Affine transform (includes scaling/shearing)
Projective(T) Projective transform

Geometric Primitives

Type Description
Hyperplane(T, n) N-dimensional hyperplane
AlignedBox(T, n) Axis-aligned bounding box
ParametrizedLine(T, n) Parametric line (origin + direction)
Scaling(T, n) Non-uniform scaling
UniformScaling(T) Uniform scaling
Translation(T, n) Pure translation

Point Set Registration

// Umeyama alignment: find optimal rigid transform from src to dst
const transform = try Zigen.umeyama(f64, 3, src_points, dst_points);