# @jingwood/graphics-math

> Math library for JavaScript 2D/3D graphics rendering.

Latest version **1.1.19** (published 2022-07-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @jingwood/graphics-math
pnpm add @jingwood/graphics-math
yarn add @jingwood/graphics-math
bun add @jingwood/graphics-math
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.19 |
| Published | 2022-07-27 |
| First published | 2020-01-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 142.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Jingwood |
| Maintainers | jingwood |

## Links

- npm: https://www.npmjs.com/package/@jingwood/graphics-math
- Repository: https://github.com/jingwood/js-graphics-math
- Issues: https://github.com/jingwood/js-graphics-math/issues
- npm.io page: https://npm.io/package/@jingwood/graphics-math

## Dependencies (1)

- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.9.2

## Recent versions

- 1.1.19 (latest) — 2022-07-27
- 1.1.18 — 2021-04-30
- 1.1.17 — 2021-01-13
- 1.1.16 — 2021-01-05
- 1.1.15 — 2020-10-30
- 1.1.14 — 2020-10-23
- 1.1.13 — 2020-10-20
- 1.1.12 — 2020-10-13
- 1.1.11 — 2020-07-19
- 1.1.10 — 2020-07-19
- 1.1.9 — 2020-06-10
- 1.1.8 — 2020-06-03
- 1.1.7 — 2020-05-06
- 1.1.6 — 2020-04-28
- 1.1.5 — 2020-04-22
- … 10 more at https://npm.io/package/@jingwood/graphics-math/versions

## README

![npm](https://img.shields.io/npm/v/@jingwood/graphics-math.svg)

# js-graphics-math

Math library for JavaScript 2D/3D graphics rendering.

# Classes

The following classes available under [src](src) folder.

- [Vector2](src/vec2.js)
- [Vector3](src/vec3.js)
- [Matrix3](src/matrix3.js)
- [Matrix4](src/matrix4.js)
- [Quaternion](src/quaternion.js)
- [BoundingBox 2D](src/bbox2.js)
- [BoundingBox 3D](src/bbox3.js)
- KDTree for 2D points
- KDTree for 3D points
- KDTree for 3D triangles
- [OCTree for 3D triangles](src/spacetree.js)
- [Ray](src/ray.js)
- [Color3 (RGB)](src/color3.js)
- [Color4 (RGBA)](src/color4.js)

# Functions

Functions below available at [src/functions.js](src/functions.js).

## Base math functions

- clamp (1D/2D/3D)
- smoothstep
- angleToArc

## Distance measuring

- distancePointToPoint (2D/3D)
- distancePointToLine (2D)
- distancePointToLineSegment (2D)
- distancePointToRect (2D)
- distancePointToPolygon (2D)
- findNearestPointToLineSegement (2D)
- findNearestPointToPolygon (2D)

## Intersecting test

- lineIntersectsLine (2D)
- lineIntersectsRect (2D)
- lineIntersectsPolygon (2D)
- rectIntersectsRect (2D)
- rectIntersectsPolygon (2D)
- checkLineParallel

## Containing test

- rectContainsPoint (2D)
- triangleContainsPoint (2D)
- polygonContainsPoint (2D)
- polygonContainsRect (2D)
- calcPolygonArea (2D)

## Ray test

- rayIntersectsPlane (3D)
- rayIntersectsTriangle (3D)
- rayIntersectsSphere (3D)
- rayIntersectsBox (3D)

## Vertex interpolation

- **calcVertexInterpolation (3D)**
  Calculate the interpolated vertex coordinate on a specified point of a 3D triangle with vertex coordinates.

# Software uses this library

- tarumae-viewer - Optimized WebGL engine for Showcase application<br/>
  [https://github.com/bulbinc/tarumae-viewer](https://github.com/bulbinc/tarumae-viewer)

# Related Libraries

- cpp-graphics-module (A C++ version of this library)<br/>
  [https://github.com/jingwood/cpp-graphics-module](https://github.com/jingwood/cpp-graphics-module)

# License

Released under MIT License.

Copyright (C) Jingwood & unvell.com, all rights reserved.

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