2.7.2 • Published 4 years ago

intersects v2.7.2

Weekly downloads
9,316
License
MIT
Repository
github
Last release
4 years ago

intersects

Collection of 2d collision/intersection checkers, supporting points, circles, circle circumferences (outline of circle), ellipses, lines, rectangles, and polygons (covex).

Live Example

https://davidfig.github.io/intersects/

Installation

npm i intersects

or

yarn add intersects

Usage

var intersects = require('intersects');

var intersected = intersects.boxBox(x1, y1, w1, h1, x2, y2, w2, h2);

or

var circleBox = require('intersects/circle-box');

var intersected = circleBox(x, y, r, x1, y1, w1, h1);

Alternative Usage

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:

<script src="https://unpkg.com/intersects/umd/intersects.min.js"></script>
<script>
    var intersected = Intersects.polygonPoint(points, x, y);
</script>

API


boxBox(x1, y1, w1, h1, x2, y2, w2, h2)

Box-box collision.

ParamMeaning
x1top-left corner of first box
y1top-left corner of first box
w1width of first box
h1height of first box
x2top-left corner of second box
y2top-left corner of second box
w2width of second box
h2height of second box

boxCircle(xb, yb, wb, hb, xc, yc, rc)

Box-circle collision.

ParamMeaning
xbtop-left corner of box
ybtop-left corner of box
wbwidth of box
hbheight of box
xccenter of circle
yccenter of circle
rcradius of circle

boxEllipse(xb, yb, wb, hb, xe, ye, rex, rey)

Box-ellipse collision.

ParamMeaning
xbtop-left corner of box
ybtop-left corner of box
wbwidth of box
hbheight of box
xecenter of ellipse
yecenter of ellipse
rexx-radius of ellipse
reyy-radius of ellipse

boxLine(xb, yb, wb, hb, x1, y1, x2, y2)

Box-line collision.

ParamMeaning
xbtop-left corner of box
ybtop-left corner of box
wbwidth of box
hbheight of box
x1first point of line
y1first point of line
x2second point of line
y2second point of line

boxPoint(x1, y1, w1, h1, x2, y2)

Box-point collision.

ParamMeaning
x1top-left corner of box
y1top-left corner of box
w1width of box
h1height of box
x2point x
y2point y

boxPolygon(xb, yb, wb, hb, points)

Box-polygon (convex) collision.

ParamMeaning
xbtop-left corner of box
ybtop-left corner of box
wbwidth of box
hbheight of box
points[x1, y1, x2, y2, ... xn, yn] of polygon

boxCircleOutline(xb, yb, wb, hb, xc, yc, rc)

Box (axis-oriented rectangle)-Circle outline (circumference of circle) collision.

ParamMeaning
xbtop-left corner of rectangle
ybtop-left corner of rectangle
wbwidth of rectangle
hbheight of rectangle
xccenter of circle outline
yccenter of circle outline
rcradius of circle outline

circleBox(xc, yc, rc, xb, yb, wb, hb)

Circle-box (axis-oriented rectangle) collision.

ParamMeaning
xccenter of circle
yccenter of circle
rcradius of circle
xbtop-left corner of rectangle
ybtop-left corner of rectangle
wbwidth of rectangle
hbheight of rectangle

circleCircle(x1, y1, r1, x2, y2, r2)

Circle-circle collision.

ParamMeaning
x1center of circle 1
y1center of circle 1
r1radius of circle 1
x2center of circle 2
y2center of circle 2
r2radius of circle 2

circleEllipse(xc, yc, rc, xe, ye, rex, rey)

Circle-ellipse collision.

ParamMeaning
x1center of circle
y1center of circle
r1radius of circle
xecenter of ellipse
yecenter of ellipse
rexx-radius of ellipse
reyy-radius of ellipse

circleLine(xc, yc, rc, x1, y1, x2, y2)

Circle-line collision.

ParamMeaning
xccenter of circle
yccenter of circle
rcradius of circle
x1first point of line
y1first point of line
x2second point of line
y2second point of line

circlePoint(x1, y1, r1, x2, y2)

Circle-point collision.

ParamMeaning
x1center of circle
y1center of circle
r1radius of circle
x2point x
y2point y

circlePolygon(xc, yc, rc, points)

Circle-polygon (convex) collision.

ParamMeaning
xccenter of circle
yccenter of circle
rcradius of circle
points[x1, y1, x2, y2, ... xn, yn] of polygon

circleCircleOutline(xc, yc, rc, xco, yco, rco)

(Not available yet.) Circle-Circle outline (circumference of circle) collision.

ParamMeaning
xccenter of circle
yccenter of circle
rcradius of circle
xcocenter of circle outline
ycocenter of circle outline
rcoradius of circle outline

lineBox(x1, y1, x2, y2, xb, yb, wb, hb)

Line-box collision.

ParamMeaning
x1point 1 of line
y1point 1 of line
x2point 2 of line
y2point 2 of line
xbtop-left of box
ybtop-left of box
wbwidth of box
hbheight of box

lineCircle(x1, y1, x2, y2, xc, yc, rc)

Line-circle collision.

ParamMeaning
x1point 1 of line
y1point 1 of line
x2point 2 of line
y2point 2 of line
xccenter of circle
yccenter of circle
rcradius of circle

lineEllipse(x1, y1, x2, y2, xe, ye, rex, rey)

Line-ellipse collision.

ParamMeaning
x1point 1 of line
y1point 1 of line
x2point 2 of line
y2point 2 of line
xecenter of ellipse
yecenter of ellipse
rexx-radius of ellipse
reyy-radius of ellipse

lineLine(x1, y1, x2, y2, x3, y3, x4, y4, thickness1, thickness2)

Line-line collision.

ParamMeaning
x1first point in line 1
y1first point in line 1
x2second point in line 1
y2second point in line 1
x3first point in line 2
y3first point in line 2
x4second point in line 2
y4second point in line 2
thickness1of line 1 (the line is centered in its thickness--see demo)
thickness2of line 2 (the line is centered in its thickness--see demo)

linePolygon(x1, y1, x2, y2, points, tolerance)

Line-polygon (convex) collision.

ParamMeaning
x1point 1 of line
y1point 1 of line
x2point 2 of line
y2point 2 of line
points[x1, y1, x2, y2, ... xn, yn] of polygon
tolerancemaximum distance of point to polygon's edges that triggers collision (see pointLine)

linePoint(x1, y1, x2, y2, xp, yp)

Line-point collision.

ParamMeaning
x1point 1 of line
y1point 1 of line
x2point 2 of line
y2point 2 of line
xppoint x
yppoint y

lineCircleOutline(x1, y1, x2, y2, xc, yc, rc)

Line-Circle outline (circumference of circle) collision.

ParamMeaning
x1first point of line
y1first point of line
x2second point of line
y2second point of line
xccenter of circle outline
yccenter of circle outline
rcradius of circle outline

pointBox(x1, y1, xb, yb, wb, hb)

Point-box collision.

ParamMeaning
x1point x
y1point y
xbtop-left corner of box
ybtop-left corner of box
wbwidth of box
hbheight of box

pointPolygon(x1, y1, points)

Point-polygon (convex) collision.

ParamMeaning
x1point x
y1point y
points[x1, y1, x2, y2, ... xn, yn] of polygon

pointLine(xp, yp, x1, y1, x2, y2)

point-line collision.

ParamMeaning
xppoint x
yppoint y
x1point 1 of line
y1point 1 of line
x2point 2 of line
y2point 2 of line

pointCircle(xp, yp, xc, yc, rc)

point-circle collision.

ParamMeaning
xppoint x
yppoint y
xccenter of circle
yccenter of circle
rcradius of circle

pointEllipse(xp, yp, xe, ye, rex, rey)

point-ellipse collision.

ParamMeaning
xppoint x
yppoint y
xecenter of circle
yecenter of circle
rexx-radius of circle
reyy-radius of circle

pointCircleOutline(x2, y2, x1, y1, r1)

Point-Circle outline (circumference of circle) collision.

ParamMeaning
x1center of circle outline
y1center of circle outline
r1radius of circle outline
x2point x
y2point y

polygonBox(points, x, y, w, h)

Polygon (convex)-box collision.

ParamMeaning
points[x1, y1, x2, y2, ... xn, yn] of polygon
xof box
yof box
wof box
hof box

polygonCircle(points, xc, yc, rc)

Polygon (convex)-circle collision.

ParamMeaning
points[x1, y1, x2, y2, ... xn, yn] of polygon
xccenter of circle
yccenter of circle
rcradius of circle

polygonEllipse(points, xe, ye, rex, rey)

Polygon (convex)-ellipse collision.

ParamMeaning
points[x1, y1, x2, y2, ... xn, yn] of polygon
xecenter of ellipse
yecenter of ellipse
rexx-radius of ellipse
reyy-radius of ellipse

polygonLine(points, x1, y1, x2, y2, tolerance)

Polygon (convex)-line collisions.

ParamMeaning
points[x1, y1, x2, y2, ... xn, yn] of polygon
x1first point in line
y1first point in line
x2second point in line
y2second point in line
tolerancemaximum distance of point to polygon's edges that triggers collision (see pointLine)

polygonPoint(points, x, y)

Polygon (convex)-point collision.

ParamMeaning
points[x1, y1, x2, y2, ... xn, yn] of polygon
xof point
yof point

polygonPolygon(points1, points2)

Polygon (convex)-polygon (convex) collision.

ParamMeaning
points1[x1, y1, x2, y2, ... xn, yn] of first polygon
points2[x1, y1, x2, y2, ... xn, yn] of second polygon

ellipseBox(xe, ye, rex, rey, x, y, w, h)

Ellipse-box collision.

ParamMeaning
xecenter of ellipse
yecenter of ellipse
rexx-radius of ellipse
reyy-radius of ellipse
xof box
yof box
wof box
hof box

ellipseCircle(xe, ye, rex, rey, xc, yc, rc)

Ellipse-circle collision.

ParamMeaning
xecenter of ellipse
yecenter of ellipse
rexx-radius of ellipse
reyy-radius of ellipse
xccenter of circle
yccenter of circle
rcradius of circle

ellipseEllipse(x1, y1, r1x, r1y, x2, y2, r2x, r2y)

Ellipse-ellipse collision.

ParamMeaning
x1center of ellipse 1
y1center of ellipse 1
r1xx-radius of ellipse 1
r1yy-radius of ellipse 1
x2center of ellipse 2
y2center of ellipse 2
r2xx-radius of ellipse 2
r2yy-radius of ellipse 2

ellipseLine(xe, ye, rex, rey, x1, y1, x2, y2)

Ellipse-line collisions.

ParamMeaning
xecenter of ellipse
yecenter of ellipse
rexx-radius of ellipse
reyy-radius of ellipse
x1first point in line
y1first point in line
x2second point in line
y2second point in line

ellipsePoint(xe, ye, rex, rey, x, y)

Ellipse-point collision.

ParamMeaning
xecenter of ellipse
yecenter of ellipse
rexx-radius of ellipse
reyy-radius of ellipse
xof point
yof point

ellipsePolygon(xe, ye, rex, rey, points2)

Ellipse-polygon (convex) collision.

ParamMeaning
xecenter of ellipse
yecenter of ellipse
rexx-radius of ellipse
reyy-radius of ellipse
xecenter of ellipse
yecenter of ellipse
rexx-radius of ellipse
reyy-radius of ellipse

circleOutlineBox(xc, yc, rc, xb, yb, wb, hb)

Circle outline (circumference of circle)-box (axis-oriented rectangle) collision.

ParamMeaning
xccenter of circle outline
yccenter of circle outline
rcradius of circle outline
xbtop-left corner of rectangle
ybtop-left corner of rectangle
wbwidth of rectangle
hbheight of rectangle

circleOutlineCircle(xco, yco, rco, xc, yc, rc)

Circle outline (circumference of circle)-circle collision.

ParamMeaning
xcocenter of circle outline
ycocenter of circle outline
rcoradius of circle outline
xccenter of circle
yccenter of circle
rcradius of circle

circleOutlineEllipse(xc, yc, rc, xe, ye, rex, rey)

(Not available yet.) Circle outline (circumference of circle)-ellipse collision.

ParamMeaning
x1center of circle outline
y1center of circle outline
r1radius of circle outline
xecenter of ellipse
yecenter of ellipse
rexx-radius of ellipse
reyy-radius of ellipse

circleOutlineLine(xc, yc, rc, x1, y1, x2, y2)

Circle outline (circumference of circle)-line collision.

ParamMeaning
xccenter of circle outline
yccenter of circle outline
rcradius of circle outline
x1first point of line
y1first point of line
x2second point of line
y2second point of line

circleOutlinePoint(x1, y1, r1, x2, y2)

Circle outline (circumference of circle)-point collision.

ParamMeaning
x1center of circle outline
y1center of circle outline
r1radius of circle outline
x2point x
y2point y

circleOutlinePolygon(xc, yc, rc, points)

(Not available yet.) Circle outline (circumference of circle)-polygon (convex) collision.

ParamMeaning
xccenter of circle outline
yccenter of circle outline
rcradius of circle outline
points[x1, y1, x2, y2, ... xn, yn] of polygon

License

MIT License

(c) 2019 YOPEY YOPEY LLC by David Figatner

2.7.2

4 years ago

2.7.1

5 years ago

2.7.0

5 years ago

2.6.0

5 years ago

2.5.2

5 years ago

2.5.1

5 years ago

2.4.5

5 years ago

2.4.4

5 years ago

2.4.3

5 years ago

2.4.2

5 years ago

2.4.1

5 years ago

2.4.0

5 years ago

2.3.0

6 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.0

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.4.2

6 years ago

1.4.1

6 years ago

1.4.0

6 years ago

1.0.0

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

10 years ago

0.0.1

10 years ago

0.0.0

10 years ago