# vec3

> 3d vector math with good unit tests

Latest version **0.2.0** (published 2026-03-30) · BSD license · 0 weekly downloads

## Install

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

## Health

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

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

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2026-03-30 |
| First published | 2013-01-02 |
| Weekly downloads | 0 |
| License | BSD |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 35.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 45 |
| Author | Andrew Kelley |
| Maintainers | rom1504, superjoe |
| Keywords | point |

## Links

- npm: https://www.npmjs.com/package/vec3
- Repository: https://github.com/PrismarineJS/node-vec3
- Homepage: https://github.com/PrismarineJS/node-vec3#readme
- Issues: https://github.com/PrismarineJS/node-vec3/issues
- npm.io page: https://npm.io/package/vec3

## Recent versions

- 0.2.0 (latest) — 2026-03-30
- 0.1.10 — 2024-01-07
- 0.1.9 — 2023-12-31
- 0.1.8 — 2023-02-23
- 0.1.7 — 2020-09-04
- 0.1.6 — 2020-07-14
- 0.1.5 — 2020-05-31
- 0.1.4 — 2020-05-15
- 0.1.3 — 2013-02-03
- 0.1.2 — 2013-01-12
- 0.1.1 — 2013-01-08
- 0.1.0 — 2013-01-08
- 0.0.8 — 2013-01-06
- 0.0.7 — 2013-01-05
- 0.0.6 — 2013-01-04
- … 5 more at https://npm.io/package/vec3/versions

## README

# vec3

[![NPM version](https://img.shields.io/npm/v/vec3.svg)](http://npmjs.com/package/vec3)
[![Build Status](https://github.com/PrismarineJS/node-vec3/workflows/CI/badge.svg)](https://github.com/PrismarineJS/node-vec3/actions?query=workflow%3A%22CI%22)

3D vector math with robust unit tests.

## Usage

```js
var v = require("vec3");

var v1 = v(1, 2, 3);
console.log(v1); // prints "(1, 2, 3)"
var v2 = v1.offset(0, 0, 1);
console.log(v2); // prints "(1, 2, 4)"
```

Or:

```js
var Vec3 = require("vec3").Vec3;

var v1 = new Vec3(1, 2, 3);
// etc...
```

More available functions are listed below in Test Coverage.

## Test Coverage

```
  v()
    ✔ no args
    ✔ x, y, z
    ✔ array
    ✔ object
    ✔ string coords
    ✔ deserialize
    ✔ invalid deserialize

  vec3
    ✔ isZero
    ✔ at
    ✔ xz
    ✔ xy
    ✔ yz
    ✔ xzy
    ✔ rounded
    ✔ round
    ✔ floored
    ✔ floor
    ✔ offset
    ✔ translate
    ✔ plus
    ✔ minus
    ✔ scaled
    ✔ abs
    ✔ angleTo
    ✔ distanceTo
    ✔ distanceSquared
    ✔ equals
    ✔ toString
    ✔ clone
    ✔ add
    ✔ subtract
    ✔ multiply
    ✔ divide
    ✔ set
    ✔ modulus
    ✔ volume
    ✔ min
    ✔ max
    ✔ update
    ✔ norm
    ✔ dot
    ✔ cross
    ✔ unit
    ✔ normalize
    ✔ scale
    ✔ xyDistanceTo
    ✔ xzDistanceTo
    ✔ yzDistanceTo
    ✔ innerProduct
    ✔ manhattanDistanceTo
    ✔ toArray

  50 passing (14ms)
```

More functions welcome in the form of pull requests.

## History

See [History](HISTORY.md)

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