You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
sliceBox - remove all polygon vertices located within a given box [bottom left, upper right]
sliceCircle - remove all polygon vertices located within a given circle [x, y, radius]
polygon-point operation / information:
inside - test if a given point is located within the polygon
on - test if a given point is located on the polygon
closest - return the polygon vertices closest to a given point
polygon-line operation / information:
lineIntersect - return a flag indicating if a line intersects the polygon
and a set of (x,y) intersection points
polygon-polygon operation / information:
intersect - perform intersection between two polygons (clipping polygon must be convex)
union - perform union between two polygons (clipping polygon must be convex)
isEqual - return true if two polygons are equal
other methods:
toString - return polygon as a human readable string
convexHull - return a polygon which is the convex hull of current polygon
radialFit - approximate polygon as a circle or an ellipse
Properties:
accuracy - used to determine floating point equality tolerance default: 1e-10
Notes:
Polygon is always closed. Last vertex is connected to first vertex.
Boolean operation (union, intersect) are allowed only if the "clipping" polygon is convex.
methods convexHull and Simplify utilize recrusive functions.
Polygon class use 'privileged' methods (a term used to describe closures within the constructor).
The following polygon operations can be chained: remove, splice, push, unshift, change, swap,
append, insertPolygon, insertVertex, reverse, sortCW, sliceBox, sliceCircle, rotate, moveAlong,
moveBy, simplify.
Examples:
// create a star shaped polygon composed of 100 pointsvar_star=newPolygon({type: 'star',inner: 100,outer: 300,points: 100});// remove all its 'inner circle' vertex and move it 50px to the right_star.sliceCircle(0,0,200).moveBy(50,0);// fit a circlevar_circleFit=_star.radialFit('circle');// check fitted circle errorconsole.log('fitted circle radius error is '+(_circleFit[2]-300)+'.\n'+'fitted circle origin error in x is '+(_circleFit[0]-50)+'.\n'+'fitted circle origin error in y is '+(_circleFit[1])+'.\n');
// create a hexagonvar_hex=newPolygon({type: 'regular',radius: 100,points: 6});// rotate hexagon by 70 degrees and move it 95px in a 45 degrees bearing_hex.rotate(0,0,70).moveAlong(45,95);// create a circlevar_circ=newPolygon({type: 'circle',radius: 45,points: 50});// move circle 110px to the right_circ.moveBy(110,0);// calcute circle and hexagon intersectionvar_intersect=_hex.intersect(_circ);// extract intersection geometrical propertiesvar_data=_intersect.data();// console.log();console.log('intersection polygon centeroid is ('+_data[0]+', '+_data[1]+')\n'+'intersection polygon perimeter is '+_data[2]+'\n'+'intersection polygon Ixx is '+_data[3]+'\n'+'intersection polygon Iyy is '+_data[4]+'\n'+'intersection polygon Ixy is '+_data[5]+'\n'+'intersection polygon centeroidal Ixx is '+_data[6]+'\n'+'intersection polygon centeroidal Iyy is '+_data[7]+'\n'+'intersection polygon centeroidal Ixy is '+_data[8]);
// create two polygonsvarsubject=newPolygon({type: 'point',points: [[50,150],[200,50],[350,150],[350,300],[250,300],[200,250],[150,350],[100,250],[100,200]]}),cliper=newPolygon({type: 'point',points: [[100,100],[300,100],[300,300],[100,300]]});// calculate their unionunion=subject.union(cliper);