0.0.1 • Published 7 years ago

gjk v0.0.1

Weekly downloads
1
License
ISC
Repository
github
Last release
7 years ago

gjk

Implementation of GJK (Gilbert-Johnson-Keerthi) algorithm for calculation distance between convex polygons and intersection detection.

Basic usage

var gjk = require('gjk');

var polygon = [
    {x: 1, y: 1},
    {x: 2, y: 1},
    {x: 2, y: 2},
    {x: 1, y: 2}
];

var notIntersectedPolygon = [
    {x: 3, y: 1},
    {x: 4, y: 1},
    {x: 4, y: 2},
    {x: 3, y: 2}
];

var distance = gjk.distance(polygon, notIntersectedPolygon); //1
var intersected = gjk.intersect(polygon, notIntersectedPolygon); //false

Polygons

Polygons might be one of the next formats

Array of objects

var polygon = [
    {x: 1, y: 1},
    {x: 2, y: 1},
    {x: 2, y: 2},
    {x: 1, y: 2}
];

Array of numbers

var polygon = [
    1, 1,
    2, 1,
    2, 2,
    1, 2
];

Array of arrays of numbers

var polygon = [
    [1, 1],
    [2, 1],
    [2, 2],
    [1, 2]
];