twodee
Two dimensional geometry manipulation
Install
$ npm install twodee
Use
Creating a simple Triangle
twodee uses xyzw for vector manipulation.
$ npm install xyzw
;;
To get es5 safe versions of all files replace /source with /es5
Creating a triangle
const triangleA = 00 00 00 10 10 00; const point0 = triangleAp0;const point1 = triangleAp1;const point2 = triangleAp2;const orientation = triangleAorientation;const centroid = triangleAcentroid;const circumcenter = triangleAcircumcenterconst area = triangleAarea;
Factory constructors
All primitives come with convenient factory constructors:
const center = 00 00;const radius = 10;const rotation = MathPI; const triangleB = Triangle2;
Collision testing
Triangles can test for collisions with points, segments and other triangles:
const intersections = ;const collision = triangleA;
All intersection tests have static versions that do not require actual objects:
const intersections = ;const collision = Triangle2
Creating a ray
; const ray = 00 00 00 10; const origin = rayorigin;const orientation = rayorientation;
Rays can test for intersections with line segments and other rays. All line intersection tests guarantee valid results for parallel and co-linear entities.
const point0 = 40 -05;const point1 = 40 05;const intersection = ;const collision = ray;
Creating a Bounding Box Rectangle
;; const box = Rectangle2; const transform = boxtransform;const extend = boxextend;const center = boxcenter;const width = boxwidth;const height = boxheight;const aspect = boxaspect;const area = boxarea;
Rectangles can test for collisions with points, segments and other rectangles
Creating a segmented line
; const lineA = PolyLine2; const points = lineApoint;const segments = lineAsegments;const closed = lineAclosed;
Segmented lines can test for collisions with points, line segments and other segment lines. All line intersection test guarantee valid results for parallel and co-linear entities.
const lineB = PolyLine2; const intersections = ;const collision = lineB;
Creating a Polygon
; const poly = ; const v0 = poly;const v1 = poly;const v2 = poly;const v3 = poly; const f0 = poly;const f1 = poly; const center = polycentroid;const area = polyarea; const vertices = polyvertex;const edges = polyedge;const faces = polyface;const point = polypoint;const drawList = polyindexList;
Polygons expose a rich api for geometry manipulations:
const e0 = poly;const e1 = poly; const f2 f3 = poly;const f4 f5 f6 = poly;
Polygons can test for collisions with Points and other Polygons
const polyB = Polygon2; const intersections = ;const collision = poly;