• Stars
    star
    530
  • Rank 81,007 (Top 2 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 6 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

a simple collection of 2d collision/intersects functions. Supports points, circles, ellipses, lines, axis-aligned boxes, and polygons

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.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Circle-point collision.

Param Meaning
x1 center of circle
y1 center of circle
r1 radius of circle
x2 point x
y2 point y

circlePolygon(xc, yc, rc, points)

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

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

(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

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

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

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

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

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

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

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

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)

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

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)

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

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

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

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

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

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

pointPolygon(x1, y1, points)

Point-polygon (convex) collision.

Param Meaning
x1 point x
y1 point y
points [x1, y1, x2, y2, ... xn, yn] of polygon

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

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

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

point-circle collision.

Param Meaning
xp point x
yp point y
xc center of circle
yc center of circle
rc radius of circle

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

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

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

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

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

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

polygonCircle(points, xc, yc, rc)

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

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

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

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

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)

polygonPoint(points, x, y)

Polygon (convex)-point collision.

Param Meaning
points [x1, y1, x2, y2, ... xn, yn] of polygon
x of point
y of point

polygonPolygon(points1, points2)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

(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

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

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

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

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

circleOutlinePolygon(xc, yc, rc, points)

(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

License

MIT License

(c) 2019 YOPEY YOPEY LLC by David Figatner

More Repositories

1

pixi-viewport

A highly configurable viewport/2D camera designed to work with pixi.js
TypeScript
997
star
2

pixi-scrollbox

a scrollbox built for pixi.js using a masked box that scrolls vertically and/or horizontally with optional scrollbars
JavaScript
169
star
3

pixi-cull

a library to visibly cull objects designed to work with pixi.js
TypeScript
105
star
4

pixi-ease

pixi.js animation library using easing functions
JavaScript
96
star
5

window-manager

A javascript-only Window Manager
JavaScript
62
star
6

pixi-intersects

shape collision / intersects library for pixi.js
JavaScript
46
star
7

pixi-dashed-line

TypeScript
33
star
8

tree

vanilla-javascript drag-and-drop UI tree
JavaScript
29
star
9

angle

Library for calculating angles in javascript
TypeScript
16
star
10

moonshot

Game Off 2020 - Shoot the Moon (like literally)
JavaScript
13
star
11

rendersheet

renders a canvas spritesheet for use with pixi.js
JavaScript
11
star
12

shape-points

Generate points for simple shapes and curves: arcs, rectangles, rounded rectangles, bezierCurveTo, bezierCurveThrough (i.e., bezier curves through specific points)
JavaScript
11
star
13

pixi-pixelate

draw proper pixelated graphic primitives (i.e., point, points, line, circle, ellipse, arc, polygon, and fill versions)
JavaScript
8
star
14

pixel-editor

An Electron-based pixel editor/animator
JavaScript
7
star
15

sortable

Vanilla drag-and-drop sortable list(s)
JavaScript
6
star
16

bezierpoints

PIXI graphics function to generate a smooth line through specific points
JavaScript
6
star
17

random

a javascript random number API with seeded support. not cryptographically sound. useful for games
JavaScript
6
star
18

viewport

viewport designed to work with pixi.js
JavaScript
5
star
19

fps

Yet another FPS indicator with graph
TypeScript
5
star
20

cordova-allow-background-audio

Cordova plugin that allows background audio to continue to play while app is running
Objective-C
4
star
21

animate

Javascript animation library for use with PIXI.js
JavaScript
4
star
22

loop

Simple and configurable game/main loop
JavaScript
4
star
23

spotlight

a simple canvas-based spotlight that can be used to highlight elements
JavaScript
4
star
24

pixel

Javascript library to generate pixel art and animated scenes
JavaScript
3
star
25

clicked

Javascript: create click event for both mouse and touch
TypeScript
3
star
26

ui

UI/windows library built on pixi.js
JavaScript
3
star
27

input

basic input support for touch, mouse, and keyboard
JavaScript
3
star
28

vanilla-gesture

JavaScript
3
star
29

renderer

wrapper for pixi.js renderer with automatic loop & clean/dirty settings
JavaScript
3
star
30

pixi-tile

A simple tile library for use with pixi.js and pixi-viewport.
JavaScript
2
star
31

vec2-recycle

another vanilla vec-2 library with recycling
JavaScript
2
star
32

calc-fontsize

calculate font-size for a given bounding box and optionally a font
JavaScript
2
star
33

json-bump

bumps the "version" entry for a JSON file
JavaScript
2
star
34

falldown

a vanilla javascript combobox (combination of dropdown and input box)
JavaScript
2
star
35

time-tracker

[WIP] A self-hosted Time Tracker using node.js, sqlite3, and HTML5
JavaScript
2
star
36

tooltip

Simple vanilla-javascript tooltip replacement.
JavaScript
2
star
37

noise

Simple 1D Noise generator in javascript
JavaScript
1
star
38

easyedit

inline editing of a single HTMLElement
JavaScript
1
star
39

yy-menu

A menu system for web apps inspired by Electron
JavaScript
1
star
40

name-generator

Yopey Yopey's Name Generator
PHP
1
star
41

dom-ease

a simple and super fast DOM animation library
JavaScript
1
star
42

settingspanel

Creates hideable UI to change settings during runtime
JavaScript
1
star
43

atom-autocorrect-text

atom.io plugin for simple autocorrects
CoffeeScript
1
star
44

debug

Javascript Debug Panels (useful for game development)
JavaScript
1
star
45

color

color javascript library
JavaScript
1
star
46

spatialHash

Javascript implementation of a 2D Spatial Hash (ES6 class and module.exports used)
JavaScript
1
star
47

jsdoc-template

jsdoc-template for my projects based on @pixi/jsdoc-template
JavaScript
1
star
48

update

update API for javascript apps
JavaScript
1
star
49

file-older-than

node.js: checks if a file modify date is older than a duration (useful for cache checks)
JavaScript
1
star