pmndrs/math

🧮 The playful web's math engine

TypeScript

1,323

386 commits

updated Sep 30, 2026

See the code

README

npm i math, surrounded by softly shimmering stars

math

Math is the playful web's math engine.

  • High performance: allocation-free, monomorphic, benchmarked
  • Tiny: mean and lean, tree-shakable, only pay for what you use
  • Portable: interops with WebGL, WebGPU, Wasm, your favourite renderer, more.
  • Data-oriented: data-in, data-out functions over caller-owned data, without owning the data lifecycle.
> npm install math
> npx skills add pmndrs/math --skill math

What's inside

Quick Start

import { type Vec3, vec3 } from 'math';

// math types are plain arrays — the constructors just return literals:
const a: Vec3 = [1, 2, 3]; // a plain-array literal
const b = vec3.fromValues(1, 2, 3); // the same as `a`
const out = vec3.create(); // returns [0, 0, 0]

// functions write into their first argument, so nothing is allocated:
vec3.add(out, a, b); // out = [2, 4, 6]
vec3.normalize(out, out); // aliasing an argument is fine

The library is grouped by domain behind subpath entrypoints. All APIs are highly tree-shakeable, only pay for what you use:

import { mat4, quat, vec3 } from 'math'; // core: vectors, quats, matrices
import { simplex3d } from 'math/noise'; // perlin / simplex noise
import { mulberry32 } from 'math/random'; // seeded rng
import { easing, spring } from 'math/time'; // easings & springs
import { fabrik2, fabrik3 } from 'math/ik'; // inverse kinematics
// also: math/color, math/geometry, math/shapes — import only what you use

Skill

Math has a skill that teaches your agent how to get the most out of it. The skill gives direction on how to design efficient, optimized and data-oriented JS code, outline common gotchas and provide some code examples that optimize memory. Try your agent with /math and see how its performance compares.

Examples

Explore the gallery →

Quaternion Look At Fibonacci Sphere OBB3 Contains Point

Convex Hull 3D Convex Hull 2D Polygon2 Decomposition

Polygon2 Triangulation Circumcircle FABRIK 2D

FABRIK 2D Snek FABRIK 3D Flow Field

Color Wheel Ridged Noise Voxel Terrain Simplex 4D Looping Noise

Simplex 2D Noise Terrain Quaternion Slerp Spring2 Tail

Easing Circle Physics Polygon2 Signed Distance

Frustum Culling Dual Quaternion Skinning

Documentation

  • API.md — every export with its signature and a one-line description, grouped by module. Flat and greppable, so it's easy to search or hand to an AI coding assistant.
  • Online API docs — the full typedoc reference, with search and cross-links.
  • What's inside — jump straight to a module or namespace.

Acknowledgements

pmndrs/math

🧮 The playful web's math engine

TypeScript

1,323

386 commits

updated Sep 30, 2026

See the code

README

npm i math, surrounded by softly shimmering stars

math

Math is the playful web's math engine.

  • High performance: allocation-free, monomorphic, benchmarked
  • Tiny: mean and lean, tree-shakable, only pay for what you use
  • Portable: interops with WebGL, WebGPU, Wasm, your favourite renderer, more.
  • Data-oriented: data-in, data-out functions over caller-owned data, without owning the data lifecycle.
> npm install math
> npx skills add pmndrs/math --skill math

What's inside

Quick Start

import { type Vec3, vec3 } from 'math';

// math types are plain arrays — the constructors just return literals:
const a: Vec3 = [1, 2, 3]; // a plain-array literal
const b = vec3.fromValues(1, 2, 3); // the same as `a`
const out = vec3.create(); // returns [0, 0, 0]

// functions write into their first argument, so nothing is allocated:
vec3.add(out, a, b); // out = [2, 4, 6]
vec3.normalize(out, out); // aliasing an argument is fine

The library is grouped by domain behind subpath entrypoints. All APIs are highly tree-shakeable, only pay for what you use:

import { mat4, quat, vec3 } from 'math'; // core: vectors, quats, matrices
import { simplex3d } from 'math/noise'; // perlin / simplex noise
import { mulberry32 } from 'math/random'; // seeded rng
import { easing, spring } from 'math/time'; // easings & springs
import { fabrik2, fabrik3 } from 'math/ik'; // inverse kinematics
// also: math/color, math/geometry, math/shapes — import only what you use

Skill

Math has a skill that teaches your agent how to get the most out of it. The skill gives direction on how to design efficient, optimized and data-oriented JS code, outline common gotchas and provide some code examples that optimize memory. Try your agent with /math and see how its performance compares.

Examples

Explore the gallery →

Quaternion Look At Fibonacci Sphere OBB3 Contains Point

Convex Hull 3D Convex Hull 2D Polygon2 Decomposition

Polygon2 Triangulation Circumcircle FABRIK 2D

FABRIK 2D Snek FABRIK 3D Flow Field

Color Wheel Ridged Noise Voxel Terrain Simplex 4D Looping Noise

Simplex 2D Noise Terrain Quaternion Slerp Spring2 Tail

Easing Circle Physics Polygon2 Signed Distance

Frustum Culling Dual Quaternion Skinning

Documentation

  • API.md — every export with its signature and a one-line description, grouped by module. Flat and greppable, so it's easy to search or hand to an AI coding assistant.
  • Online API docs — the full typedoc reference, with search and cross-links.
  • What's inside — jump straight to a module or namespace.

Acknowledgements

Project health

npm

Latest release

0.1.0 · Sep 11, 2026

Releases this year

1

Significant stargazers

Brent Vatne

4,534 followers · starred Nov 2021

chessai

262 followers · starred Sep 2026

Jesse Talavera

275 followers · starred Sep 2026

Cody Olsen

426 followers · starred Apr 2022