# frustum-intersects

> Determines if camera's frustum intersects with aabb box and sphere

Latest version **0.2.4** (published 2024-01-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install frustum-intersects
pnpm add frustum-intersects
yarn add frustum-intersects
bun add frustum-intersects
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.4 |
| Published | 2024-01-29 |
| First published | 2018-08-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | fuzhenn |
| Maintainers | fuzhenn |
| Keywords | webgl, frustum |

## Links

- npm: https://www.npmjs.com/package/frustum-intersects
- Repository: https://github.com/fuzhenn/frustum-intersects
- Issues: https://github.com/fuzhenn/frustum-intersects/issues
- npm.io page: https://npm.io/package/frustum-intersects

## Recent versions

- 0.2.4 (latest) — 2024-01-29
- 0.2.3 — 2024-01-29
- 0.2.2 — 2022-01-25
- 0.2.1 — 2022-01-25
- 0.2.0 — 2020-08-17
- 0.1.0 — 2018-08-11

## README

# Frustum-Intersects

[![NPM Version](https://img.shields.io/npm/v/frustum-intersects.svg)](https://github.com/fuzhenn/frustum-intersects) [![CircleCI](https://circleci.com/gh/fuzhenn/frustum-intersects.svg?style=shield)](https://circleci.com/gh/fuzhenn/frustum-intersects)

A zero-dependency lib extracted from [THREE.js](https://github.com/mrdoob/three.js) to determine if camera's frustum intersects with given box or sphere.

## Usage

### npm
```shell
npm i frustum-intersects --save
```

```js
import { intersectsBox, intersectsSphere } from 'frustum-intersects';

const ret = intersectsBox([
            1, 0, 0, 0,
            0, 1, 0, 0,
            0, 0, 1, 0,
            0, 0, 0, 1],
           [[-1,-1,-1], [1,1,1]]);

const ret2 = intersectsSphere([
            1, 0, 0, 0,
            0, 1, 0, 0,
            0, 0, 1, 0,
            0, 0, 0, 1],
           [[0, 0, 0], 1]);
```

### Browser
```html
<script src="https://cdn.jsdelivr.net/npm/frustum-intersects/dist/frustum-intersects.js"></script>

<script>
const ret = frustum.intersectsBox(matrix, box);
</script>

```

## API

### intersectsBox(matrix, box, mask)

* `matrix` camera's 4x4 projection view matrix array, compatible with gl-matrix
* `box` the aabb box, [[minx, miny, minz], [maxx, maxy, maxz]]
* `mask` A 6 chars string mask (e.g. `"111111"`) of frustum planes, plane with mask of `0` will always return `true`

### intersectsSphere(matrix, sphere, mask)

* `matrix` camera's 4x4 projection view matrix array, compatible with gl-matrix
* `sphere` sphere, [[centerx, centery, centerz], radius]
* `mask` A 6 chars string mask (e.g. `"111111"`) of frustum planes, plane with mask of `0` will always return `true`

>> the planes' order of mask is `{right}{left}{bottom}{top}{z-far}{z-near}`,

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