- Notifications
You must be signed in to change notification settings - Fork49
a simple collection of 2d collision/intersects functions. Supports points, circles, ellipses, lines, axis-aligned boxes, and polygons
License
davidfig/intersects
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Collection of 2d collision/intersection checkers, supporting points, circles, circle circumferences (outline of circle), ellipses, lines, rectangles, and polygons (covex).
https://davidfig.github.io/intersects/
npm i intersects
or
yarn add intersects
varintersects=require('intersects');varintersected=intersects.boxBox(x1,y1,w1,h1,x2,y2,w2,h2);
or
varcircleBox=require('intersects/circle-box');varintersected=circleBox(x,y,r,x1,y1,w1,h1);
If you don't want to package the library using rollup, browserify, etc., you can also include the prepackaged library, which includes a global Intersects object:
<scriptsrc="https://unpkg.com/intersects/umd/intersects.min.js"></script><script>varintersected=Intersects.polygonPoint(points,x,y);</script>
- box (AABB / axis-aligned rectangle)
- circle
- line
- point
- polygon (convex)
- ellipse
- circleOutline (only the circumference of circle)
Box-box collision.
Param | Meaning |
---|---|
x1 | top-left corner of first box |
y1 | top-left corner of first box |
w1 | width of first box |
h1 | height of first box |
x2 | top-left corner of second box |
y2 | top-left corner of second box |
w2 | width of second box |
h2 | height of second box |
Box-circle collision.
Param | Meaning |
---|---|
xb | top-left corner of box |
yb | top-left corner of box |
wb | width of box |
hb | height of box |
xc | center of circle |
yc | center of circle |
rc | radius of circle |
Box-ellipse collision.
Param | Meaning |
---|---|
xb | top-left corner of box |
yb | top-left corner of box |
wb | width of box |
hb | height of box |
xe | center of ellipse |
ye | center of ellipse |
rex | x-radius of ellipse |
rey | y-radius of ellipse |
Box-line collision.
Param | Meaning |
---|---|
xb | top-left corner of box |
yb | top-left corner of box |
wb | width of box |
hb | height of box |
x1 | first point of line |
y1 | first point of line |
x2 | second point of line |
y2 | second point of line |
Box-point collision.
Param | Meaning |
---|---|
x1 | top-left corner of box |
y1 | top-left corner of box |
w1 | width of box |
h1 | height of box |
x2 | point x |
y2 | point y |
Box-polygon (convex) collision.
Param | Meaning |
---|---|
xb | top-left corner of box |
yb | top-left corner of box |
wb | width of box |
hb | height of box |
points | [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 rectangle |
yb | top-left corner of rectangle |
wb | width of rectangle |
hb | height of rectangle |
xc | center of circle outline |
yc | center of circle outline |
rc | radius of circle outline |
Circle-box (axis-oriented rectangle) collision.
Param | Meaning |
---|---|
xc | center of circle |
yc | center of circle |
rc | radius of circle |
xb | top-left corner of rectangle |
yb | top-left corner of rectangle |
wb | width of rectangle |
hb | height of rectangle |
Circle-circle collision.
Param | Meaning |
---|---|
x1 | center of circle 1 |
y1 | center of circle 1 |
r1 | radius of circle 1 |
x2 | center of circle 2 |
y2 | center of circle 2 |
r2 | radius of circle 2 |
Circle-ellipse collision.
Param | Meaning |
---|---|
x1 | center of circle |
y1 | center of circle |
r1 | radius of circle |
xe | center of ellipse |
ye | center of ellipse |
rex | x-radius of ellipse |
rey | y-radius of ellipse |
Circle-line collision.
Param | Meaning |
---|---|
xc | center of circle |
yc | center of circle |
rc | radius of circle |
x1 | first point of line |
y1 | first point of line |
x2 | second point of line |
y2 | second point of line |
Circle-point collision.
Param | Meaning |
---|---|
x1 | center of circle |
y1 | center of circle |
r1 | radius of circle |
x2 | point x |
y2 | point y |
Circle-polygon (convex) collision.
Param | Meaning |
---|---|
xc | center of circle |
yc | center of circle |
rc | radius of circle |
points | [x1, y1, x2, y2, ... xn, yn] of polygon |
(Not available yet.) Circle-Circle outline (circumference of circle) collision.
Param | Meaning |
---|---|
xc | center of circle |
yc | center of circle |
rc | radius of circle |
xco | center of circle outline |
yco | center of circle outline |
rco | radius of circle outline |
Line-box collision.
Param | Meaning |
---|---|
x1 | point 1 of line |
y1 | point 1 of line |
x2 | point 2 of line |
y2 | point 2 of line |
xb | top-left of box |
yb | top-left of box |
wb | width of box |
hb | height of box |
Line-circle collision.
Param | Meaning |
---|---|
x1 | point 1 of line |
y1 | point 1 of line |
x2 | point 2 of line |
y2 | point 2 of line |
xc | center of circle |
yc | center of circle |
rc | radius of circle |
Line-ellipse collision.
Param | Meaning |
---|---|
x1 | point 1 of line |
y1 | point 1 of line |
x2 | point 2 of line |
y2 | point 2 of line |
xe | center of ellipse |
ye | center of ellipse |
rex | x-radius of ellipse |
rey | y-radius of ellipse |
Line-line collision.
Param | Meaning |
---|---|
x1 | first point in line 1 |
y1 | first point in line 1 |
x2 | second point in line 1 |
y2 | second point in line 1 |
x3 | first point in line 2 |
y3 | first point in line 2 |
x4 | second point in line 2 |
y4 | second point in line 2 |
thickness1 | 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 line |
y1 | point 1 of line |
x2 | point 2 of line |
y2 | point 2 of line |
points | [x1, y1, x2, y2, ... xn, yn] of polygon |
tolerance | maximum distance of point to polygon's edges that triggers collision (see pointLine) |
Line-point collision.
Param | Meaning |
---|---|
x1 | point 1 of line |
y1 | point 1 of line |
x2 | point 2 of line |
y2 | point 2 of line |
xp | point x |
yp | point y |
Line-Circle outline (circumference of circle) collision.
Param | Meaning |
---|---|
x1 | first point of line |
y1 | first point of line |
x2 | second point of line |
y2 | second point of line |
xc | center of circle outline |
yc | center of circle outline |
rc | radius of circle outline |
Point-box collision.
Param | Meaning |
---|---|
x1 | point x |
y1 | point y |
xb | top-left corner of box |
yb | top-left corner of box |
wb | width of box |
hb | height of box |
Point-polygon (convex) collision.
Param | Meaning |
---|---|
x1 | point x |
y1 | point y |
points | [x1, y1, x2, y2, ... xn, yn] of polygon |
point-line collision.
Param | Meaning |
---|---|
xp | point x |
yp | point y |
x1 | point 1 of line |
y1 | point 1 of line |
x2 | point 2 of line |
y2 | point 2 of line |
point-circle collision.
Param | Meaning |
---|---|
xp | point x |
yp | point y |
xc | center of circle |
yc | center of circle |
rc | radius of circle |
point-ellipse collision.
Param | Meaning |
---|---|
xp | point x |
yp | point y |
xe | center of circle |
ye | center of circle |
rex | x-radius of circle |
rey | y-radius of circle |
Point-Circle outline (circumference of circle) collision.
Param | Meaning |
---|---|
x1 | center of circle outline |
y1 | center of circle outline |
r1 | radius of circle outline |
x2 | point x |
y2 | point y |
Polygon (convex)-box collision.
Param | Meaning |
---|---|
points | [x1, y1, x2, y2, ... xn, yn] of polygon |
x | of box |
y | of box |
w | of box |
h | of box |
Polygon (convex)-circle collision.
Param | Meaning |
---|---|
points | [x1, y1, x2, y2, ... xn, yn] of polygon |
xc | center of circle |
yc | center of circle |
rc | radius of circle |
Polygon (convex)-ellipse collision.
Param | Meaning |
---|---|
points | [x1, y1, x2, y2, ... xn, yn] of polygon |
xe | center of ellipse |
ye | center of ellipse |
rex | x-radius of ellipse |
rey | y-radius of ellipse |
Polygon (convex)-line collisions.
Param | Meaning |
---|---|
points | [x1, y1, x2, y2, ... xn, yn] of polygon |
x1 | first point in line |
y1 | first point in line |
x2 | second point in line |
y2 | second point in line |
tolerance | 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 polygon |
x | of point |
y | of point |
Polygon (convex)-polygon (convex) collision.
Param | Meaning |
---|---|
points1 | [x1, y1, x2, y2, ... xn, yn] of first polygon |
points2 | [x1, y1, x2, y2, ... xn, yn] of second polygon |
Ellipse-box collision.
Param | Meaning |
---|---|
xe | center of ellipse |
ye | center of ellipse |
rex | x-radius of ellipse |
rey | y-radius of ellipse |
x | of box |
y | of box |
w | of box |
h | of box |
Ellipse-circle collision.
Param | Meaning |
---|---|
xe | center of ellipse |
ye | center of ellipse |
rex | x-radius of ellipse |
rey | y-radius of ellipse |
xc | center of circle |
yc | center of circle |
rc | radius of circle |
Ellipse-ellipse collision.
Param | Meaning |
---|---|
x1 | center of ellipse 1 |
y1 | center of ellipse 1 |
r1x | x-radius of ellipse 1 |
r1y | y-radius of ellipse 1 |
x2 | center of ellipse 2 |
y2 | center of ellipse 2 |
r2x | x-radius of ellipse 2 |
r2y | y-radius of ellipse 2 |
Ellipse-line collisions.
Param | Meaning |
---|---|
xe | center of ellipse |
ye | center of ellipse |
rex | x-radius of ellipse |
rey | y-radius of ellipse |
x1 | first point in line |
y1 | first point in line |
x2 | second point in line |
y2 | second point in line |
Ellipse-point collision.
Param | Meaning |
---|---|
xe | center of ellipse |
ye | center of ellipse |
rex | x-radius of ellipse |
rey | y-radius of ellipse |
x | of point |
y | of point |
Ellipse-polygon (convex) collision.
Param | Meaning |
---|---|
xe | center of ellipse |
ye | center of ellipse |
rex | x-radius of ellipse |
rey | y-radius of ellipse |
xe | center of ellipse |
ye | center of ellipse |
rex | x-radius of ellipse |
rey | y-radius of ellipse |
Circle outline (circumference of circle)-box (axis-oriented rectangle) collision.
Param | Meaning |
---|---|
xc | center of circle outline |
yc | center of circle outline |
rc | radius of circle outline |
xb | top-left corner of rectangle |
yb | top-left corner of rectangle |
wb | width of rectangle |
hb | height of rectangle |
Circle outline (circumference of circle)-circle collision.
Param | Meaning |
---|---|
xco | center of circle outline |
yco | center of circle outline |
rco | radius of circle outline |
xc | center of circle |
yc | center of circle |
rc | radius of circle |
(Not available yet.) Circle outline (circumference of circle)-ellipse collision.
Param | Meaning |
---|---|
x1 | center of circle outline |
y1 | center of circle outline |
r1 | radius of circle outline |
xe | center of ellipse |
ye | center of ellipse |
rex | x-radius of ellipse |
rey | y-radius of ellipse |
Circle outline (circumference of circle)-line collision.
Param | Meaning |
---|---|
xc | center of circle outline |
yc | center of circle outline |
rc | radius of circle outline |
x1 | first point of line |
y1 | first point of line |
x2 | second point of line |
y2 | second point of line |
Circle outline (circumference of circle)-point collision.
Param | Meaning |
---|---|
x1 | center of circle outline |
y1 | center of circle outline |
r1 | radius of circle outline |
x2 | point x |
y2 | point y |
(Not available yet.) Circle outline (circumference of circle)-polygon (convex) collision.
Param | Meaning |
---|---|
xc | center of circle outline |
yc | center of circle outline |
rc | radius of circle outline |
points | [x1, y1, x2, y2, ... xn, yn] of polygon |
MIT License
(c) 2019YOPEY YOPEY LLC byDavid Figatner