Skip to content
github-actions[bot] edited this page Mar 1, 2026 · 5 revisions

layout: default title: Home

libmath2

A comprehensive C/C++ mathematics library for 2D/3D vector operations, matrix transformations, quaternion rotations, collision detection, and more.

Overview

libmath2 provides a complete set of mathematical primitives for graphics, game development, and physics simulations. All core types support multiple numeric precisions (f64, f32, i64, i32, i16, i8, u64, u32, u16, u8) with consistent naming conventions and first-class C/C++ interoperability.

Quick Start

cmake -B build
cmake --build build
#include <lm2.h>

lm2_v3 pos = lm2_v3_make_f32(1.0f, 2.0f, 3.0f);
lm2_v3 dir = lm2_v3_norm_f32(pos);
float  len = lm2_v3_length_f32(pos);

Modules

Module Description
Vectors 2D, 3D, and 4D vector types with full arithmetic and utility operations
Vector Specifics Dot/cross products, length, distance, normalize, angle, rotation, reflection, projection
Matrices 3x2, 3x3, and 4x4 transformation matrices
Scalar Scalar math: rounding, clamping, interpolation, power, sqrt
Trigonometry Trig functions with angle wrapping and interpolation
Safe Ops Overflow-checked arithmetic for all numeric types
Ranges 2D, 3D, and 4D axis-aligned bounding boxes
Geometry 2D 2D shapes: circles, AABBs, capsules, edges, planes, polygons, triangles
Geometry 3D 3D shapes: spheres, AABBs, capsules, edges, planes, triangles
Cameras 2D orthographic and 3D perspective/orthographic camera types with view matrix and space transform helpers
Quaternions Rotation quaternions with SLERP, Euler, and axis-angle conversions
Bezier Curves Linear, quadratic, and cubic Bezier evaluation, derivatives, splitting
Easings 30 easing functions for animation and tweening
Noise Perlin and Voronoi noise generation
Hash Non-cryptographic hash functions and FNV-1a
Extensions C11 generics, C++ overloads, and operator overloads

Naming Convention

All functions follow the pattern:

lm2_<module>_<operation>_<type>

For example:

  • lm2_v3_add_f32 — Add two 3D float vectors
  • lm2_m4x4_inverse_f64 — Invert a 4x4 double matrix
  • lm2_quat_slerp_f32 — Spherical interpolation between float quaternions

Clone this wiki locally