Nonlinear Performance Magnification

npm

Need private packages and team management tools?Check out npm Orgs. »

line-circle-collision

1.1.3 • Public • Published

line-circle-collision

stable

Performs a line-circle collision test, returning true if they intersect. Algorithm from 2D Game Collision by Thomas Schwarzl.

var collide = require('line-circle-collision')
 
var circle = [5, 5],
    radius = 25,
    a = [5, 6],
    b = [10, 10]
 
var hit = collide(a, b, circle, radius)
console.log(hit)

You may also be interested in:

Usage

NPM

collide(a, b, circle, radius[, nearest])

Performs a collision test with the line a-b and the given circle. Returns true if collision occurred.

a, b, and circle are expected to be 2D vectors in the form of an array.

If nearest is passed, the nearest point found during the intersection test will be stored into that vector. This is useful if you need to find the nearest point along the line for the intersection test. If the hit returns false, you should not expect the value of nearest to have changed.

License

MIT, see LICENSE.md for details.

install

npm i line-circle-collision

Downloadsweekly downloads

52

version

1.1.3

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability