Polygon is a JavaScript object that allows you to adjust a polygon by manipulating Handles: one for each vertex of the polygon. This code is used in the 2D Geometry section of this site
Polygon is a sub-class of the Shape object.
constructor - new Polygon(svgNode);
This method creates a new Polygon object. All initialization is handled by the init() method. All parameters for this method are described below
init() initialized all properties for this object. This method parses the points attribute of the svgNode. Each vertex is used to create an associated Handle object.
svgNode is an SVG polygon element to be managed by this object.
realize() constructs the SVG DOM nodes needed to visualize the handles of this widget. Any event listeners that are used by this object will be registered by this method.
refresh() applies the handle positions to the SVG element associated with this object.
registerHandles() adds all handles used by this object to the mouser's handle list.
unregisterHandles() removes all handles used by this object from the mouser's handle list.
selectHandles() set the current select value for all handles used by this object.
showHandles() sets the current visibility value for all handles used by this object.
getIntersectionParams() : IntersectionParams;
This method returns an IntersectionParams object to specify this shape's name and the necessary parameters to find the intersection of this shape with another. The name is used by the Intersection object to determine which intersection routine to call.
pointInPolygon(point) : boolean;
pointInPolygon() determines if the specified Point2D is within the polygon.
getArea() returns the area of the polygon managed by this object. Negative values are returned for polygons whose vertices are drawn in a clockwise order. Please note that the current implementation does not return correct values for self-intersecting polygons.
isClockwise() determines if the vertices of the polygon are in a clockwise order.
isCounterClockwise() : boolean;
isCounterClockwise() determines if the vertices of the polygon are in a counter-clockwise order.
isConcave() determines if the polygon is concave.
isConvex() determines if the polygon is convex.
setCallback() sets the callback property of all handles to the specified value.
This example allows you to adjust the vertices of the polygons within the SVG document. Here is a brief summary of the editing procedures:
Polygon.js - the polygon object only...cannot be used in isolation
2D.js.gz - all objects needed to use this object and other 2D geometry objects