JavaScript must be enabled in order for you to use JSXGraph and JSXGraph reference. However, it seems JavaScript is either disabled or not supported by your browser.

Class Index | File Index

Elements

Classes


Class JXG.Polygon

JXG.GeometryElement
      ↳ JXG.Polygon

Polygon stores all style and functional properties that are required to draw and to interactact with a polygon.

Defined in: polygon.js.
Extends JXG.GeometryElement.

Class Summary
Constructor Attributes Constructor Name and Description
 
JXG.Polygon(board, vertices, attributes)
Creates a new instance of JXG.Polygon.
Fields borrowed from class JXG.GeometryElement:
_org_type, _pos, ancestors, baseElement, board, childElements, dash, descendants, draft, dump, elementClass, elType, fillColor, fillOpacity, fixed, frozen, hasLabel, highlight, highlighted, highlightFillColor, highlightFillOpacity, highlightStrokeColor, highlightStrokeOpacity, highlightStrokeWidth, id, isDraggable, isReal, lastDragTime, methodMap, mouseover, name, needsRegularUpdate, needsUpdate, notExistingParents, numTraces, parents, quadraticform, rendNode, scalable, shadow, snapToGrid, stdform, strokeColor, strokeOpacity, strokeWidth, subs, symbolic, trace, traceAttributes, traces, transformations, type, visible, visProp, withLabel
Field Summary
Field Attributes Field Name and Description
 
References to the border lines of the polygon.
 
References to the points defining the polygon.
Fields borrowed from class JXG.GeometryElement:
_org_type, _pos, ancestors, baseElement, board, childElements, dash, descendants, draft, dump, elementClass, elType, fillColor, fillOpacity, fixed, frozen, hasLabel, highlight, highlighted, highlightFillColor, highlightFillOpacity, highlightStrokeColor, highlightStrokeOpacity, highlightStrokeWidth, id, isDraggable, isReal, lastDragTime, methodMap, mouseover, name, needsRegularUpdate, needsUpdate, notExistingParents, numTraces, parents, quadraticform, rendNode, scalable, shadow, snapToGrid, stdform, strokeColor, strokeOpacity, strokeWidth, subs, symbolic, trace, traceAttributes, traces, transformations, type, visible, visProp, withLabel
Method Summary
Method Attributes Method Name and Description
 
Add more points to the polygon.
 
Area()
Area of (not self-intersecting) polygon
 
Bounding box of a polygon.
 
Finds the index to a given point reference.
 
return TextAnchor
 
hasPoint(x, y)
Checks whether (x,y) is near the polygon.
 
hideElement(borderless)
Hide the polygon including its border lines.
 
insertPoints(idx, p)
Adds more points to the vertex list of the polygon, starting with index
 
intersect(polygon)
Generic method for the intersection of this polygon with another polygon.
 
This method removes the SVG or VML nodes of the lines and the filled area from the renderer, to remove the object completely you should use JXG.Board#removeObject.
 
Removes given set of vertices from the polygon
 
setPositionDirectly(method, coords, oldcoords)
Moves the polygon by the difference of two coordinates.
 
showElement(borderless)
Make the element visible.
<private>  
Algorithm by Sutherland and Hodgman to compute the intersection of two convex polygons.
 
Uses the boards renderer to update the polygon.
Methods borrowed from class JXG.GeometryElement:
_set, addChild, addDescendants, addParents, addRotation, addTransform, animate, bounds, clearTrace, cloneToBackground, countChildren, createGradient, createLabel, draggable, generatePolynomial, getAttribute, getAttributes, getLabelAnchor, getName, getParents, getProperty, getType, handleSnapToGrid, labelColor, noHighlight, normalize, prepareUpdate, removeChild, removeDescendants, resolveShortcuts, setArrow, setAttribute, setDash, setLabel, setLabelText, setName, setParents, setPosition, setProperty, snapToPoints, update
Events borrowed from class JXG.GeometryElement:
attribute, attribute:<attribute><attribute>, down, drag, mousedown, mousedrag, mousemove, mouseout, mouseover, mouseup, move, out, over, touchdown, touchdrag, touchup, up
Class Detail
JXG.Polygon(board, vertices, attributes)
Creates a new instance of JXG.Polygon.
Parameters:
{JXG.Board} board
Reference to the board the polygon is to be drawn on.


{Array} vertices
Unique identifiers for the points defining the polygon. Last point must be first point. Otherwise, the first point will be added at the list.


{Object} attributes
An object which contains properties as given in JXG.Options.elements and JXG.Options.polygon.


Field Detail
{Array} borders
References to the border lines of the polygon.

{Array} vertices
References to the points defining the polygon. The last vertex is the same as the first vertex.
Method Detail
{JXG.Polygon} addPoints(p)
Add more points to the polygon. The new points will be inserted at the end.
Parameters:
{JXG.Point} p
Arbitrary number of points
Returns:
{JXG.Polygon} Reference to the polygon

{Number} Area()
Area of (not self-intersecting) polygon
Returns:
{Number} Area of (not self-intersecting) polygon

{Array} boundingBox()
Bounding box of a polygon. The bounding box is an array of four numbers: the first two numbers determine the upper left corner, the last two number determine the lower right corner of the bounding box. The width and height of a polygon can then determined like this:
Returns:
{Array} Array containing four numbers: [minX, maxY, maxX, minY]
Examples:
var box = polygon.boundingBox();
var width = box[2] - box[0];
var height = box[1] - box[3];

findPoint(p)
Finds the index to a given point reference.
Parameters:
{JXG.Point} p
Reference to an element of type JXG.Point

getTextAnchor()
return TextAnchor

{Boolean} hasPoint(x, y)
Checks whether (x,y) is near the polygon.
Parameters:
{Number} x
Coordinate in x direction, screen coordinates.
{Number} y
Coordinate in y direction, screen coordinates.
Returns:
{Boolean} Returns true, if (x,y) is inside or at the boundary the polygon, otherwise false.

hideElement(borderless)
Hide the polygon including its border lines. It will still exist but not visible on the board.
Parameters:
{Boolean} borderless Optional, Default: false
If set to true, the polygon is treated as a polygon without borders, i.e. the borders will not be hidden.

{JXG.Polygon} insertPoints(idx, p)
Adds more points to the vertex list of the polygon, starting with index
Parameters:
{Number} idx
The position where the new vertices are inserted, starting with 0.
{JXG.Point} p
Arbitrary number of points to insert.
Returns:
{JXG.Polygon} Reference to the polygon object

{Array} intersect(polygon)
Generic method for the intersection of this polygon with another polygon. The parent object is the clipping polygon, it expects as parameter a polygon to be clipped. Both polygons have to be convex. Calls JXG.Polygon#sutherlandHodgman.
Parameters:
{JXG.Polygon} polygon
Polygon which will be clipped.
Returns:
{Array} of (normalized homogeneous user) coordinates (i.e. [z, x, y], where z==1 in most cases, representing the vertices of the intersection polygon.
Examples:
 // Static intersection of two polygons pol1 and pol2
 var pol1 = board.create('polygon', [[-2, 3], [-4, -3], [2, 0], [4, 4]], {
               name:'pol1', withLabel: true,
               fillColor: 'yellow'
            });
 var pol2 = board.create('polygon', [[-2, -3], [-4, 1], [0, 4], [5, 1]], {
               name:'pol2', withLabel: true
            });

 // Static version:
 // the intersection polygon does not adapt to changes of pol1 or pol2.
 var pol3 = board.create('polygon', pol1.intersect(pol2), {fillColor: 'blue'});

					
					
 // Dynamic intersection of two polygons pol1 and pol2
 var pol1 = board.create('polygon', [[-2, 3], [-4, -3], [2, 0], [4, 4]], {
               name:'pol1', withLabel: true,
               fillColor: 'yellow'
            });
 var pol2 = board.create('polygon', [[-2, -3], [-4, 1], [0, 4], [5, 1]], {
               name:'pol2', withLabel: true
            });

 // Dynamic version:
 // the intersection polygon does  adapt to changes of pol1 or pol2.
 // For this a curve element is used.
 var curve = board.create('curve', [[],[]], {fillColor: 'blue', fillOpacity: 0.4});
 curve.updateDataArray = function() {
     var mat = JXG.Math.transpose(pol1.intersect(pol2));

     if (mat.length == 3) {
         this.dataX = mat[1];
         this.dataY = mat[2];
     } else {
         this.dataX = [];
         this.dataY = [];
     }
 };
 board.update();

					
					

remove()
This method removes the SVG or VML nodes of the lines and the filled area from the renderer, to remove the object completely you should use JXG.Board#removeObject.

{JXG.Polygon} removePoints(p)
Removes given set of vertices from the polygon
Parameters:
{JXG.Point} p
Arbitrary number of vertices as JXG.Point elements or index numbers
Returns:
{JXG.Polygon} Reference to the polygon

{JXG.Polygon} setPositionDirectly(method, coords, oldcoords)
Moves the polygon by the difference of two coordinates.
Parameters:
{Number} method
The type of coordinates used here. Possible values are JXG.COORDS_BY_USER and JXG.COORDS_BY_SCREEN.
{Array} coords
coordinates in screen/user units
{Array} oldcoords
previous coordinates in screen/user units
Returns:
{JXG.Polygon} this element

showElement(borderless)
Make the element visible.
Parameters:
{Boolean} borderless Optional, Default: false
If set to true, the polygon is treated as a polygon without borders, i.e. the borders will not be shown.

<private> {Array} sutherlandHodgman(polygon)
Algorithm by Sutherland and Hodgman to compute the intersection of two convex polygons. The polygon itself is the clipping polygon, it expects as parameter a polygon to be clipped. See wikipedia entry. Called by JXG.Polygon#intersect.
Parameters:
{JXG.Polygon} polygon
Polygon which will be clipped.
Returns:
{Array} of (normalized homogeneous user) coordinates (i.e. [z, x, y], where z==1 in most cases, representing the vertices of the intersection polygon.

updateRenderer()
Uses the boards renderer to update the polygon.

Documentation generated by JsDoc Toolkit 2.4.0 on Tue Jul 05 2016 11:01:14 GMT+0200 (CEST)