Skip to content
Harsh Singh edited this page Jul 23, 2022 · 8 revisions

Following functions are exported by the collision.js module.

circleInCircle

Circle In Circle Collision

Params

  • x1 - center of first circle
  • y1 - center of first circle
  • r1 - radius of first circle
  • x2 - center of second circle
  • y2 - center of second circle
  • r2 - radius of second circle

Example

Bottlecap.Collision.circleInCircle(0, 0, 50, 10, 10, 50); // returns true
Bottlecap.Collision.circleInCircle(0, 0, 50, 100, 100, 50); // returns false

pointInCircle

Point In Circle

Params

  • x1 - point's x coord
  • y1 - point's y coord
  • cx - center of circle
  • cy - center of circle
  • r - radius of circle

Example

Bottlecap.Collision.pointInCircle(20, 20, 10, 10, 50); // returns true
Bottlecap.Collision.pointInCircle(-190, -180, 10, 10, 50); // returns false

rectInRect

Rect In Rect

Params

  • x1 - left of rect1
  • y1 - top of rect1
  • w1 - width of rect1
  • h1 - height of rect1
  • x2 - left of rect2
  • y2 - top of rect2
  • w2 - width of rect2
  • h2 - height of rect2

Example

Bottlecap.Collision.rectInRect(0, 0, 100, 100, 50, 0, 100, 100); // true
Bottlecap.Collision.rectInRect(-500, 0, 100, 100, 50, 0, 100, 100); // false

pointInRect

Point In Rect

Params

  • x - point's x coord
  • y - point's y coord
  • rx - left of rect
  • ry - top of rect
  • rw - width of rect
  • rh - height of rect

Example

Bottlecap.Collision.pointInRect(0, 0, 100, 100, 50, 0, 100, 100); // true
Bottlecap.Collision.pointInRect(-500, 0, 100, 100, 50, 0, 100, 100); // false

circleInRect

Circle In Rect Collision

Params

  • cx - center of circle
  • cy - center of circle
  • r - radius of circle
  • rx - left of rect
  • ry - top of rect
  • rw - width of rect
  • rh - height of rect

Example

Bottlecap.Collision.circleInRect(0, 0, 50, 0, 0, 100, 100); // returns true
Bottlecap.Collision.circleInRect(0, 0, 50, 300, 200, 100, 100); // returns false
Clone this wiki locally