# math

> a collection of math helpers for graphics and simulations

Latest version **0.1.0** (published 2026-09-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install math
pnpm add math
yarn add math
bun add math
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2026-09-11 |
| First published | 2011-06-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 1.9 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 1335 |
| Author | Isaac Mason |
| Maintainers | isaacmason, krispyaa |
| Keywords | math, vector, matrix, quaternion, euler, random, noise |

## Links

- npm: https://www.npmjs.com/package/math
- Repository: https://github.com/pmndrs/math
- Issues: https://github.com/pmndrs/math/issues
- npm.io page: https://npm.io/package/math

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2026-09-11
- 0.0.0-canary-20261106-bb2138c2 (canary) — 2026-11-06
- 0.0.0-canary-20261104-7c33bcd6 — 2026-11-04
- 0.0.0-canary-20261026-7c55d752 — 2026-10-26
- 0.0.0-canary-20261026-91978db2 — 2026-10-26
- 0.0.0-canary-20261019-82387b5d — 2026-10-19
- 0.0.0-canary-20261012-67df8ec8 — 2026-10-12
- 0.0.0-canary-20261012-46811259 — 2026-10-12
- 0.0.0-canary-20261012-7bd9f603 — 2026-10-12
- 0.0.0-canary-20261012-3a426576 — 2026-10-12
- 0.0.0-canary-20261012-e2331ee2 — 2026-10-12
- 0.0.0-canary-20260930-56e1c4d3 — 2026-09-30
- 0.0.0-canary-20260930-832d875e — 2026-09-30
- 0.0.0-canary-20260930-ae781dee — 2026-09-30
- 0.0.0-canary-20260930-a8792b32 — 2026-09-30
- … 46 more at https://npm.io/package/math/versions

## README

# math

math is a collection of math helpers for graphics and simulations.

- **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.

```sh
> npm install math@canary
```

## What's inside

| Import | Description | Contents |
| --- | --- | --- |
| [`math`](API.md#api-math) | Vectors, quaternions, euler angles & matrices | [`vec2`](API.md#api-math-vec2) [`vec3`](API.md#api-math-vec3) [`vec4`](API.md#api-math-vec4) [`euler`](API.md#api-math-euler) [`quat`](API.md#api-math-quat) [`quat2`](API.md#api-math-quat2) [`mat2`](API.md#api-math-mat2) [`mat2d`](API.md#api-math-mat2d) [`mat3`](API.md#api-math-mat3) [`mat4`](API.md#api-math-mat4) [`spherical`](API.md#api-math-spherical) [`polar`](API.md#api-math-polar) [`EPSILON`](API.md#epsilon) [`round`](API.md#round) [`equals`](API.md#equals) [`fade`](API.md#fade) [`lerp`](API.md#lerp) [`lagrange`](API.md#lagrange) [`binomial`](API.md#binomial) [`clamp`](API.md#clamp) [`repeat`](API.md#repeat) [`remap`](API.md#remap) [`remapClamp`](API.md#remapclamp) [`DEGREES_TO_RADIANS`](API.md#degrees_to_radians) [`RADIANS_TO_DEGREES`](API.md#radians_to_degrees) [`degreesToRadians`](API.md#degreestoradians) [`radiansToDegrees`](API.md#radianstodegrees) [`wrapAngle`](API.md#wrapangle) [`deltaAngle`](API.md#deltaangle) |
| [`math/shapes`](API.md#api-math-shapes) | Shape primitives & spatial queries | [`box2`](API.md#api-math-shapes-box2) [`box3`](API.md#api-math-shapes-box3) [`obb3`](API.md#api-math-shapes-obb3) [`plane3`](API.md#api-math-shapes-plane3) [`sphere`](API.md#api-math-shapes-sphere) [`circle`](API.md#api-math-shapes-circle) [`segment2`](API.md#api-math-shapes-segment2) [`polygon2`](API.md#api-math-shapes-polygon2) [`triangle2`](API.md#api-math-shapes-triangle2) [`triangle3`](API.md#api-math-shapes-triangle3) [`raycast3`](API.md#api-math-shapes-raycast3) [`frustum`](API.md#api-math-shapes-frustum) |
| [`math/geometry`](API.md#api-math-geometry) | Geometric algorithms | [`circumcircle`](API.md#circumcircle) [`decomposePolygon2Quick`](API.md#decomposepolygon2quick) [`decomposePolygon2Quality`](API.md#decomposepolygon2quality) [`triangulatePolygon2`](API.md#triangulatepolygon2) [`quickhull2`](API.md#quickhull2) [`quickhull3`](API.md#quickhull3) |
| [`math/time`](API.md#api-math-time) | Easing & spring animation | [`easing`](API.md#api-math-time-easing) [`spring`](API.md#api-math-time-spring) [`spring2`](API.md#api-math-time-spring2) [`spring3`](API.md#api-math-time-spring3) [`spring4`](API.md#api-math-time-spring4) |
| [`math/random`](API.md#api-math-random) | Seeded random number generators | [`isaac32`](API.md#api-math-random-isaac32) [`isaac64`](API.md#api-math-random-isaac64) [`mulberry32`](API.md#api-math-random-mulberry32) [`random`](API.md#api-math-random-random) |
| [`math/noise`](API.md#api-math-noise) | Perlin, simplex & worley noise, plus fractal helpers | [`perlin2d`](API.md#api-math-noise-perlin2d) [`perlin3d`](API.md#api-math-noise-perlin3d) [`simplex2d`](API.md#api-math-noise-simplex2d) [`simplex3d`](API.md#api-math-noise-simplex3d) [`simplex4d`](API.md#api-math-noise-simplex4d) [`worley2d`](API.md#api-math-noise-worley2d) [`worley3d`](API.md#api-math-noise-worley3d) [`fbm`](API.md#fbm) [`ridged`](API.md#ridged) [`billow`](API.md#billow) [`domainWarp2`](API.md#domainwarp2) [`domainWarp3`](API.md#domainwarp3) [`curl2`](API.md#curl2) [`curl3`](API.md#curl3) |
| [`math/color`](API.md#api-math-color) | Color & colorspace utilities | [`color`](API.md#api-math-color-color) [`colorspace`](API.md#api-math-color-colorspace) [`hsl`](API.md#api-math-color-hsl) |
| [`math/ik`](API.md#api-math-ik) | Inverse kinematics | [`fabrik2`](API.md#api-math-ik-fabrik2) [`fabrik3`](API.md#api-math-ik-fabrik3) |


## Quick Start

```ts
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:

```ts
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
```

## Examples

<table>
  <tr>
    <td align="center">
      <a href="https://pmndrs.github.io/math/examples/#example-look-at">
        <img src="./examples/public/screenshots/example-look-at.png" width="180" height="120" style="object-fit:cover;"/><br/>
        Look At
      </a>
    </td>
    <td align="center">
      <a href="https://pmndrs.github.io/math/examples/#example-fibonacci-sphere">
        <img src="./examples/public/screenshots/example-fibonacci-sphere.png" width="180" height="120" style="object-fit:cover;"/><br/>
        Fibonacci Sphere
      </a>
    </td>
    <td align="center">
      <a href="https://pmndrs.github.io/math/examples/#example-contains-point">
        <img src="./examples/public/screenshots/example-contains-point.png" width="180" height="120" style="object-fit:cover;"/><br/>
        Contains Point
      </a>
    </td>
  </tr>
  <tr>
    <td align="center">
      <a href="https://pmndrs.github.io/math/examples/#example-convex-hull-3d">
        <img src="./examples/public/screenshots/example-convex-hull-3d.png" width="180" height="120" style="object-fit:cover;"/><br/>
        Convex Hull 3D
      </a>
    </td>
    <td align="center">
      <a href="https://pmndrs.github.io/math/examples/#example-convex-hull-2d">
        <img src="./examples/public/screenshots/example-convex-hull-2d.png" width="180" height="120" style="object-fit:cover;"/><br/>
        Convex Hull 2D
      </a>
    </td>
    <td align="center">
      <a href="https://pmndrs.github.io/math/examples/#example-polygon2-decomposition">
        <img src="./examples/public/screenshots/example-polygon2-decomposition.png" width="180" height="120" style="object-fit:cover;"/><br/>
        Polygon2 Decomposition
      </a>
    </td>
  </tr>
  <tr>
    <td align="center">
      <a href="https://pmndrs.github.io/math/examples/#example-polygon2-triangulation">
        <img src="./examples/public/screenshots/example-polygon2-triangulation.png" width="180" height="120" style="object-fit:cover;"/><br/>
        Polygon2 Triangulation
      </a>
    </td>
    <td align="center">
      <a href="https://pmndrs.github.io/math/examples/#example-circumcircle">
        <img src="./examples/public/screenshots/example-circumcircle.png" width="180" height="120" style="object-fit:cover;"/><br/>
        Circumcircle
      </a>
    </td>
    <td align="center">
      <a href="https://pmndrs.github.io/math/examples/#example-fabrik-2d">
        <img src="./examples/public/screenshots/example-fabrik-2d.png" width="180" height="120" style="object-fit:cover;"/><br/>
        FABRIK 2D
      </a>
    </td>
  </tr>
  <tr>
    <td align="center">
      <a href="https://pmndrs.github.io/math/examples/#example-fabrik-2d-snek">
        <img src="./examples/public/screenshots/example-fabrik-2d-snek.png" width="180" height="120" style="object-fit:cover;"/><br/>
        FABRIK 2D Snek
      </a>
    </td>
    <td align="center">
      <a href="https://pmndrs.github.io/math/examples/#example-fabrik-3d">
        <img src="./examples/public/screenshots/example-fabrik-3d.png" width="180" height="120" style="object-fit:cover;"/><br/>
        FABRIK 3D
      </a>
    </td>
    <td align="center">
      <a href="https://pmndrs.github.io/math/examples/#example-flow-field">
        <img src="./examples/public/screenshots/example-flow-field.png" width="180" height="120" style="object-fit:cover;"/><br/>
        Flow Field
      </a>
    </td>
  </tr>
  <tr>
    <td align="center">
      <a href="https://pmndrs.github.io/math/examples/#example-color-wheel">
        <img src="./examples/public/screenshots/example-color-wheel.png" width="180" height="120" style="object-fit:cover;"/><br/>
        Color Wheel
      </a>
    </td>
    <td align="center">
      <a href="https://pmndrs.github.io/math/examples/#example-ridged-noise-voxel-terrain">
        <img src="./examples/public/screenshots/example-ridged-noise-voxel-terrain.png" width="180" height="120" style="object-fit:cover;"/><br/>
        Ridged Noise Voxel Terrain
      </a>
    </td>
    <td align="center">
      <a href="https://pmndrs.github.io/math/examples/#example-simplex-4d-looping-noise">
        <img src="./examples/public/screenshots/example-simplex-4d-looping-noise.png" width="180" height="120" style="object-fit:cover;"/><br/>
        Simplex 4D Looping Noise
      </a>
    </td>
  </tr>
  <tr>
    <td align="center">
      <a href="https://pmndrs.github.io/math/examples/#example-simplex-2d-noise-terrain">
        <img src="./examples/public/screenshots/example-simplex-2d-noise-terrain.png" width="180" height="120" style="object-fit:cover;"/><br/>
        Simplex 2D Noise Terrain
      </a>
    </td>
    <td align="center">
      <a href="https://pmndrs.github.io/math/examples/#example-quaternion-slerp">
        <img src="./examples/public/screenshots/example-quaternion-slerp.png" width="180" height="120" style="object-fit:cover;"/><br/>
        Quaternion Slerp
      </a>
    </td>
    <td align="center">
      <a href="https://pmndrs.github.io/math/examples/#example-spring">
        <img src="./examples/public/screenshots/example-spring.png" width="180" height="120" style="object-fit:cover;"/><br/>
        Spring
      </a>
    </td>
  </tr>
  <tr>
    <td align="center">
      <a href="https://pmndrs.github.io/math/examples/#example-easing">
        <img src="./examples/public/screenshots/example-easing.png" width="180" height="120" style="object-fit:cover;"/><br/>
        Easing
      </a>
    </td>
  </tr>
</table>

## Documentation

- **[API.md](./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](https://pmndrs.github.io/math/docs/)** — the full typedoc reference, with search and cross-links.
- **[What's inside](#whats-inside)** — jump straight to a module or namespace.

## Acknowledgements:

- The vec*, quat*, mat* code started life as a port of mathcat, which started as a TypeScript port of glMatrix (https://glmatrix.net/)
- The simplex noise is adapted from https://github.com/josephg/noisejs
- Thank you [@kaleb](https://github.com/kaleb) for the npm package name!

---
_Source: https://npm.io/package/math · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
