Polygon

From JSXGraph Wiki
Revision as of 12:35, 23 June 2020 by A WASSERMANN (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Polygon defined by existing points

To construct a polygon an array of already constructed points is required. So we first have to construct at least three points:

var b1 = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-4, 2, 6, -4]});
var p1 = b1.create('point',[0,0], {name:'X', size:4});
var p2 = b1.create('point',[2,-1], {name:'B', size:4});
var p3 = b1.create('point',[-2,-3], {name:'C', size:4});
var p4 = b1.create('point',[-1,-1], {name:'D', size:4});
var p5 = b1.create('point',[3,1], {name:'E', size:4});

Note that the "size" attribute is optional as is the attribute "name". Next we create a polygon through these five points "A" to "E".

var poly = b1.create('polygon',["X","B","C","D","E"], { borders:{strokeColor:'black'} });

Of course we can also use the JavaScript objects p1 to p5:

var poly = b1.create('polygon',[p1,p2,p3,p4,p5], { borders:{strokeColor:'black'} });

The result is the same: