a simple collection of 2d collision/intersects functions, supporting points, circles, circle outlines (circumference), lines, axis-aligned boxes, and polygons (convex)
npm install intersectsCollection of 2d collision/intersection checkers, supporting points, circles, circle circumferences (outline of circle), ellipses, lines, rectangles, and polygons (covex).
```
npm i intersects`
or`
yarn add intersects
`js
var intersects = require('intersects');
var intersected = intersects.boxBox(x1, y1, w1, h1, x2, y2, w2, h2);
`
or
`js
var circleBox = require('intersects/circle-box');
var intersected = circleBox(x, y, r, x1, y1, w1, h1);
`
`html`
* box (AABB / axis-aligned rectangle)
* boxBox(x1, y1, w1, h1, x2, y2, w2, h2)
* boxCircle(xb, yb, wb, hb, xc, yc, rc) |
* boxEllipse(xb, yb, wb, hb, xe, ye, rex, rey)
* boxLine(xb, yb, wb, hb, x1, y1, x2, y2)
* boxPoint(x1, y1, w1, h1, x2, y2)
* boxPolygon(xb, yb, wb, hb, points)
* boxCircleOutline(xb, yb, wb, hb, xc, yc, rc)
* circle
* circleBox(xc, yc, rc, xb, yb, wb, hb)
* circleCircle(x1, y1, r1, x2, y2, r2)
* circleEllipse(xc, yc, rc, xe, ye, rex, rey)
* circleLine(xc, yc, rc, x1, y1, x2, y2)
* circlePoint(x1, y1, r1, x2, y2)
* circlePolygon(xc, yc, rc, points, tolerance)
* (N/A) circleCircleOutline(xc, yc, rc, xco, yco, rco)
* line
* lineBox(x1, y1, x2, y2, xb, yb, wb, hb)
* lineCircle(x1, y1, x2, y2, xc, yc, rc)
* lineEllipse(x1, y1, x2, y2, xe, ye, rex, rey)
* lineLine(x1, y1, x2, y2, x3, y3, x4, y4)
* linePolygon(x1, y1, x2, y2, points, tolerance)
* linePoint(x1, y1, x2, y2, xp, yp)
* lineCircleOutline(x1, y1, x2, y2, xc, yc, rc)
* point
* pointBox(x1, y1, xb, yb, wb, hb)
* pointPolygon(x1, y1, points)
* pointLine(xp, yp, x1, y1, x2, y2)
* pointCircle(xp, yp, xc, yc, rc)
* pointEllipse(xp, yp, xe, ye, rex, rey)
* pointCircleOutline(x2, y2, x1, y1, r1)
* polygon (convex)
* polygonBox(points, x, y, w, h)
* polygonCircle(points, xc, yc, rc, tolerance)
* polygonEllipse(points, xe, ye, rex, rey)
* polygonLine(points, x1, y1, x2, y2, tolerance)
* polygonPoint(points, x, y)
* polygonPolygon(points1, points2)
* ellipse
* ellipseBox(xe, ye, rex, rey, x, y, w, h)
* ellipseCircle(xe, ye, rex, rey, xc, yc, rc)
* ellipseEllipse(x1, y1, r1x, r1y, x2, y2, r2x, r2y
* ellipseLine(xe, ye, rex, rey, x1, y1, x2, y2)
* ellipsePoint(xe, ye, rex, rey, x, y)
* ellipsePolygon(xe, ye, rex, rey, points2)
* circleOutline (only the circumference of circle)
* circleOutlineBox(xc, yc, rc, xb, yb, wb, hb)
* (N/A) circleOutlineCircle(xco, yco, rco, xc, yc, rc)
* (N/A) circleOutlineEllipse(xc, yc, rc, xe, ye, rex, rey)
* circleOutlineLine(xc, yc, rc, x1, y1, x2, y2)
* circleOutlinePoint(x1, y1, r1, x2, y2)
* (N/A) circleOutlinePolygon(xc, yc, rc, points)
---
Box-box collision.
Param | Meaning
---|---
x1 | top-left corner of first boxy1 | top-left corner of first boxw1 | width of first boxh1 | height of first boxx2 | top-left corner of second boxy2 | top-left corner of second boxw2 | width of second boxh2 | height of second box
---
Box-circle collision.
Param | Meaning
---|---
xb | top-left corner of boxyb | top-left corner of boxwb | width of boxhb | height of boxxc | center of circleyc | center of circlerc | radius of circle
---
Box-ellipse collision.
Param | Meaning
---|---
xb | top-left corner of boxyb | top-left corner of boxwb | width of boxhb | height of boxxe | center of ellipseye | center of ellipserex | x-radius of ellipserey | y-radius of ellipse
---
Box-line collision.
Param | Meaning
---|---
xb | top-left corner of boxyb | top-left corner of boxwb | width of boxhb | height of boxx1 | first point of liney1 | first point of linex2 | second point of liney2 | second point of line
---
Box-point collision.
Param | Meaning
---|---
x1 | top-left corner of boxy1 | top-left corner of boxw1 | width of boxh1 | height of boxx2 | point xy2 | point y
---
Box-polygon (convex) collision.
Param | Meaning
---|---
xb | top-left corner of boxyb | top-left corner of boxwb | width of boxhb | height of boxpoints | [x1, y1, x2, y2, ... xn, yn] of polygon
---
Box (axis-oriented rectangle)-Circle outline (circumference of circle) collision.
Param | Meaning
---|---
xb | top-left corner of rectangleyb | top-left corner of rectanglewb | width of rectanglehb | height of rectanglexc | center of circle outlineyc | center of circle outlinerc | radius of circle outline
---
Circle-box (axis-oriented rectangle) collision.
Param | Meaning
---|---
xc | center of circleyc | center of circlerc | radius of circlexb | top-left corner of rectangleyb | top-left corner of rectanglewb | width of rectanglehb | height of rectangle
---
Circle-circle collision.
Param | Meaning
---|---
x1 | center of circle 1y1 | center of circle 1r1 | radius of circle 1x2 | center of circle 2y2 | center of circle 2r2 | radius of circle 2
---
Circle-ellipse collision.
Param | Meaning
---|---
x1 | center of circley1 | center of circler1 | radius of circlexe | center of ellipseye | center of ellipserex | x-radius of ellipserey | y-radius of ellipse
---
Circle-line collision.
Param | Meaning
---|---
xc | center of circleyc | center of circlerc | radius of circlex1 | first point of liney1 | first point of linex2 | second point of liney2 | second point of line
---
Circle-point collision.
Param | Meaning
---|---
x1 | center of circley1 | center of circler1 | radius of circlex2 | point xy2 | point y
---
Circle-polygon (convex) collision.
Param | Meaning
---|---
xc | center of circleyc | center of circlerc | radius of circlepoints | [x1, y1, x2, y2, ... xn, yn] of polygon
---
(Not available yet.) Circle-Circle outline (circumference of circle) collision.
Param | Meaning
---|---
xc | center of circleyc | center of circlerc | radius of circlexco | center of circle outlineyco | center of circle outlinerco | radius of circle outline
---
Line-box collision.
Param | Meaning
---|---
x1 | point 1 of liney1 | point 1 of linex2 | point 2 of liney2 | point 2 of linexb | top-left of boxyb | top-left of boxwb | width of boxhb | height of box
---
Line-circle collision.
Param | Meaning
---|---
x1 | point 1 of liney1 | point 1 of linex2 | point 2 of liney2 | point 2 of linexc | center of circleyc | center of circlerc | radius of circle
---
Line-ellipse collision.
Param | Meaning
---|---
x1 | point 1 of liney1 | point 1 of linex2 | point 2 of liney2 | point 2 of linexe | center of ellipseye | center of ellipserex | x-radius of ellipserey | y-radius of ellipse
---
Line-line collision.
Param | Meaning
---|---
x1 | first point in line 1y1 | first point in line 1x2 | second point in line 1y2 | second point in line 1x3 | first point in line 2y3 | first point in line 2x4 | second point in line 2y4 | second point in line 2thickness1 | of line 1 (the line is centered in its thickness--see demo)thickness2 | of line 2 (the line is centered in its thickness--see demo)
---
Line-polygon (convex) collision.
Param | Meaning
---|---
x1 | point 1 of liney1 | point 1 of linex2 | point 2 of liney2 | point 2 of linepoints | [x1, y1, x2, y2, ... xn, yn] of polygontolerance | maximum distance of point to polygon's edges that triggers collision (see pointLine)
---
Line-point collision.
Param | Meaning
---|---
x1 | point 1 of liney1 | point 1 of linex2 | point 2 of liney2 | point 2 of linexp | point xyp | point y
---
Line-Circle outline (circumference of circle) collision.
Param | Meaning
---|---
x1 | first point of liney1 | first point of linex2 | second point of liney2 | second point of linexc | center of circle outlineyc | center of circle outlinerc | radius of circle outline
---
Point-box collision.
Param | Meaning
---|---
x1 | point xy1 | point yxb | top-left corner of boxyb | top-left corner of boxwb | width of boxhb | height of box
---
Point-polygon (convex) collision.
Param | Meaning
---|---
x1 | point xy1 | point ypoints | [x1, y1, x2, y2, ... xn, yn] of polygon
---
point-line collision.
Param | Meaning
---|---
xp | point xyp | point yx1 | point 1 of liney1 | point 1 of linex2 | point 2 of liney2 | point 2 of line
---
point-circle collision.
Param | Meaning
---|---
xp | point xyp | point yxc | center of circleyc | center of circlerc | radius of circle
---
point-ellipse collision.
Param | Meaning
---|---
xp | point xyp | point yxe | center of circleye | center of circlerex | x-radius of circlerey | y-radius of circle
---
Point-Circle outline (circumference of circle) collision.
Param | Meaning
---|---
x1 | center of circle outliney1 | center of circle outliner1 | radius of circle outlinex2 | point xy2 | point y
---
Polygon (convex)-box collision.
Param | Meaning
---|---
points | [x1, y1, x2, y2, ... xn, yn] of polygonx | of boxy | of boxw | of boxh | of box
---
Polygon (convex)-circle collision.
Param | Meaning
---|---
points | [x1, y1, x2, y2, ... xn, yn] of polygonxc | center of circleyc | center of circlerc | radius of circle
---
Polygon (convex)-ellipse collision.
Param | Meaning
---|---
points | [x1, y1, x2, y2, ... xn, yn] of polygonxe | center of ellipseye | center of ellipserex | x-radius of ellipserey | y-radius of ellipse
---
Polygon (convex)-line collisions.
Param | Meaning
---|---
points | [x1, y1, x2, y2, ... xn, yn] of polygonx1 | first point in liney1 | first point in linex2 | second point in liney2 | second point in linetolerance | maximum distance of point to polygon's edges that triggers collision (see pointLine)
---
Polygon (convex)-point collision.
Param | Meaning
---|---
points | [x1, y1, x2, y2, ... xn, yn] of polygonx | of pointy | of point
---
Polygon (convex)-polygon (convex) collision.
Param | Meaning
---|---
points1 | [x1, y1, x2, y2, ... xn, yn] of first polygonpoints2 | [x1, y1, x2, y2, ... xn, yn] of second polygon
---
Ellipse-box collision.
Param | Meaning
---|---
xe | center of ellipseye | center of ellipserex | x-radius of ellipserey | y-radius of ellipsex | of boxy | of boxw | of boxh | of box
---
Ellipse-circle collision.
Param | Meaning
---|---
xe | center of ellipseye | center of ellipserex | x-radius of ellipserey | y-radius of ellipsexc | center of circleyc | center of circlerc | radius of circle
---
Ellipse-ellipse collision.
Param | Meaning
---|---
x1 | center of ellipse 1y1 | center of ellipse 1r1x | x-radius of ellipse 1r1y | y-radius of ellipse 1x2 | center of ellipse 2y2 | center of ellipse 2r2x | x-radius of ellipse 2r2y | y-radius of ellipse 2
---
Ellipse-line collisions.
Param | Meaning
---|---
xe | center of ellipseye | center of ellipserex | x-radius of ellipserey | y-radius of ellipsex1 | first point in liney1 | first point in linex2 | second point in liney2 | second point in line
---
Ellipse-point collision.
Param | Meaning
---|---
xe | center of ellipseye | center of ellipserex | x-radius of ellipserey | y-radius of ellipsex | of pointy | of point
---
Ellipse-polygon (convex) collision.
Param | Meaning
---|---
xe | center of ellipseye | center of ellipserex | x-radius of ellipserey | y-radius of ellipsexe | center of ellipseye | center of ellipserex | x-radius of ellipserey | y-radius of ellipse
---
Circle outline (circumference of circle)-box (axis-oriented rectangle) collision.
Param | Meaning
---|---
xc | center of circle outlineyc | center of circle outlinerc | radius of circle outlinexb | top-left corner of rectangleyb | top-left corner of rectanglewb | width of rectanglehb | height of rectangle
---
Circle outline (circumference of circle)-circle collision.
Param | Meaning
---|---
xco | center of circle outlineyco | center of circle outlinerco | radius of circle outlinexc | center of circleyc | center of circlerc | radius of circle
---
(Not available yet.) Circle outline (circumference of circle)-ellipse collision.
Param | Meaning
---|---
x1 | center of circle outliney1 | center of circle outliner1 | radius of circle outlinexe | center of ellipseye | center of ellipserex | x-radius of ellipserey | y-radius of ellipse
---
Circle outline (circumference of circle)-line collision.
Param | Meaning
---|---
xc | center of circle outlineyc | center of circle outlinerc | radius of circle outlinex1 | first point of liney1 | first point of linex2 | second point of liney2 | second point of line
---
Circle outline (circumference of circle)-point collision.
Param | Meaning
---|---
x1 | center of circle outliney1 | center of circle outliner1 | radius of circle outlinex2 | point xy2 | point y
---
(Not available yet.) Circle outline (circumference of circle)-polygon (convex) collision.
Param | Meaning
---|---
xc | center of circle outlineyc | center of circle outlinerc | radius of circle outlinepoints | [x1, y1, x2, y2, ... xn, yn]` of polygon
MIT License
(c) 2019 YOPEY YOPEY LLC by David Figatner