- 
                Notifications
    
You must be signed in to change notification settings  - Fork 0
 
Collision
        Harsh Singh edited this page Nov 29, 2021 
        ·
        8 revisions
      
    Following functions are exported by the collision.js module.
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
 
import { circleInCircle } from './bottlecap/collision.js';
circleInCircle(0, 0, 50, 10, 10, 50); // returns true
circleInCircle(0, 0, 50, 100, 100, 50); // returns falseParams
- x1 - point's x coord
 - y1 - point's y coord
 - cx - center of circle
 - cy - center of circle
 - r - radius of circle
 
import { pointInCircle } from './bottlecap/collision.js';
pointInCircle(20, 20, 10, 10, 50); // returns true
pointInCircle(-190, -180, 10, 10, 50); // returns falseParams
- 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
 
import { rectInRect } from './bottlecap/collision.js';
rectInRect(0, 0, 100, 100, 50, 0, 100, 100); // true
rectInRect(-500, 0, 100, 100, 50, 0, 100, 100); // falseParams
- 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
 
import { pointInRect } from './bottlecap/collision.js';
pointInRect(0, 0, 100, 100, 50, 0, 100, 100); // true
pointInRect(-500, 0, 100, 100, 50, 0, 100, 100); // falseParams
- 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
 
import { circleInRect } from './bottlecap/collision.js';
circleInRect(0, 0, 50, 0, 0, 100, 100); // returns true
circleInRect(0, 0, 50, 300, 200, 100, 100); // returns false