# JSXGraph Reference

## 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

- _global_
- Angle
- Arc
- Arrow
- Arrowparallel
- Axis
- Bisector
- Bisectorlines
- Button
- Cardinalspline
- Checkbox
- Circle
- Circumcenter
- Circumcircle
- CircumcircleArc
- CircumcircleSector
- Conic
- Curve
- Derivative
- Ellipse
- Functiongraph
- Glider
- Grid
- Group
- Hatch
- Hyperbola
- Image
- Incenter
- Incircle
- Inequality
- Input
- Integral
- Intersection
- JXG
- JXG.AbstractRenderer
- JXG.Board
- JXG.C
- JXG.CA
- JXG.CanvasRenderer
- JXG.Circle
- JXG.Complex
- JXG.Composition
- JXG.Coords
- JXG.CoordsElement
- JXG.Curve
- JXG.Dump
- JXG.EventEmitter
- JXG.GeometryElement
- JXG.GeonextParser
- JXG.Group
- JXG.Image
- JXG.JessieCode
- JXG.JSXGraph
- JXG.Line
- JXG.Math
- JXG.Math.Geometry
- JXG.Math.Numerics
- JXG.Math.Poly
- JXG.Math.Poly.Monomial
- JXG.Math.Poly.Polynomial
- JXG.Math.Poly.Ring
- JXG.Math.Statistics
- JXG.Math.Symbolic
- JXG.NoRenderer
- JXG.Options
- JXG.Point
- JXG.Polygon
- JXG.Server
- JXG.Server.modules
- JXG.SVGRenderer
- JXG.Text
- JXG.Ticks
- JXG.Transformation
- JXG.Turtle
- JXG.Util
- JXG.Util.Base64
- JXG.Util.Unzip
- JXG.Util.UTF8
- JXG.VMLRenderer
- JXG.XML
- Label
- Line
- Locus
- MajorArc
- MajorSector
- Midpoint
- MinorArc
- MinorSector
- Mirrorelement
- Mirrorpoint
- NonReflexAngle
- Normal
- Orthogonalprojection
- OtherIntersection
- Parabola
- Parallel
- Parallelpoint
- Perpendicular
- PerpendicularPoint
- PerpendicularSegment
- Point
- PolarLine
- PolePoint
- Polygon
- Quadtree
- RadicalAxis
- Reflection
- ReflexAngle
- RegularPolygon
- Riemannsum
- Sector
- Segment
- Semicircle
- Slider
- Slopetriangle
- Spline
- Stepfunction
- Tangent
- Tapemeasure
- Text
- Ticks
- Tracecurve
- Transformation
- Turtle

# 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, inherits, 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, transitionDuration, type, visible, visProp, visPropCalc, withLabel

Field Summary
Field Attributes | Field Name and Description
--- | ---
| borders References to the border lines of the polygon.
| vertices 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, inherits, 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, transitionDuration, type, visible, visProp, visPropCalc, withLabel

Method Summary
Method Attributes | Method Name and Description
--- | ---
| addPoints(p) Add more points to the polygon.
| Area() Area of (not self-intersecting) polygon
| boundingBox() Bounding box of a polygon.
| findPoint(p) Finds the index to a given point reference.
| getTextAnchor() 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 `<i`
| intersect(polygon) Generic method for the intersection of this polygon with another polygon.
| Perimeter() Perimeter of polygon.
| 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.
| removePoints(p) 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> | sutherlandHodgman(polygon) Algorithm by Sutherland and Hodgman to compute the intersection of two convex polygons.
| updateRenderer() 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, fullUpdate, generatePolynomial, getAttribute, getAttributes, getLabelAnchor, getName, getParents, getProperty, getType, handleSnapToGrid, labelColor, noHighlight, normalize, prepareUpdate, removeChild, removeDescendants, resolveShortcuts, setArrow, setAttribute, setDash, setDisplayRendNode, setLabel, setLabelText, setName, setParents, setPosition, setProperty, snapToPoints, update, updateVisibility

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 `<i`

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();

{Number} Perimeter()
Perimeter of polygon.

Returns:
  {Number} Perimeter of polygon in user units.

Examples:

    var p = [[0.0, 2.0], [2.0, 1.0], [4.0, 6.0], [1.0, 3.0]];

    var pol = board.create('polygon', p, {hasInnerPoints: true});
    var t = board.create('text', [5, 5, function() { return pol.Perimeter(); }]);

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.