# segseg

> 2d segment to segment intersection detection

Latest version **1.0.0** (published 2020-07-19) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2020-07-19 |
| First published | 2012-12-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=12 |
| Dependencies | 0 |
| Unpacked size | 8.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Elijah Insua |
| Maintainers | tmpvar |
| Keywords | 2dmath, intersection, collision, 2d |

## Links

- npm: https://www.npmjs.com/package/segseg
- Repository: https://github.com/tmpvar/segseg
- Homepage: https://github.com/tmpvar/segseg#readme
- Issues: https://github.com/tmpvar/segseg/issues
- npm.io page: https://npm.io/package/segseg

## 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

- 1.0.0 (latest) — 2020-07-19
- 0.2.2 — 2016-06-09
- 0.2.1 — 2014-01-27
- 0.2.0 — 2013-02-18
- 0.1.1 — 2012-12-16
- 0.1.0 — 2012-12-16

## README

# segseg

[![Build Status](https://travis-ci.org/tmpvar/segseg.svg?branch=master)](https://travis-ci.org/tmpvar/segseg)

Intersection detection between two line segments in 2d space.


## Usage

```javascript
import segseg from 'segseg'


/*
                (0, 5)
                   |
  (-10, 0) --------+-------  (10, 0)
                   |
                (0, -5)
*/

const isect = [ NaN, NaN ] // the output vector where collision point is stored

//                       seg 1                   seg 2
//                ┌-------------------┐   ┌-----------------┐
if (segseg(isect, [ -10, 0 ], [ 10, 0 ],  [ 0, 5 ], [ 0, -5 ]))
    console.log('intersected!', isect.join(','))  // output:   intersected! 0,0

```


## Node compatibility

This is a pure es module, and requires node v12+ to run. However if you're using a popular bundler such as rollup, webpack, etc. This should be compatible with most frontend setups too.


## Credits

This code was ported from Mukesh Prasad's [example implementation](http://www.realtimerendering.com/resources/GraphicsGems/gemsii/xlines.c) which was included in graphics gems 2.

Internally the code uses a point-segment check for some edge cases, from https://gist.github.com/mattdesl/47412d930dcd8cd765c871a65532ffac

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