JSPM

triangle-circle-collision

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7
  • Score
    100M100P100Q54184F
  • License MIT

detect if a 2D triangle and circle collide

Package Exports

  • triangle-circle-collision

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (triangle-circle-collision) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

triangle-circle-collision

stable

Detects if a circle collides with or is fully inside of a triangle. This is well suited for 2D canvas games with an upper-left origin.

var collide = require('triangle-circle-collision')

var triangle = [[350,300], [450,450], [350, 450]]
var point = [25, 15],
    radius = 15

//returns true if collision occurs
console.log( collide(triangle, point, radius) )

Usage

NPM

collide(triangle, circle, radius[, clockwise])

Returns true if the circle intersects a triangle vertex, edge, or if it's fully enclosed by the triangle. This will test the orientation of the triangle assuming a coordinate space like that in HTML5 canvas (upper left).

If the direction is known, you can provide a boolean to clockwise to avoid the additional orientation check.

License

MIT, see LICENSE.md for details.