# Difference between revisions of "Polygon"

From JSXGraph Wiki

(New page: == Polygon defined by existing points == One possibility to construct a polygon is to give it an array of already constructed points. So we first have to construct at least three points: <...) |
m (Added to category examples) |
||

Line 35: | Line 35: | ||

</script> | </script> | ||

</html> | </html> | ||

+ | |||

+ | |||

+ | |||

+ | [[Category:Examples]] |

## Revision as of 20:51, 20 October 2008

## Polygon defined by existing points

One possibility to construct a polygon is to give it an array of already constructed points. So we first have to construct at least three points:

```
var b = JXG.JSXGraph.initBoard('jxgbox', {originX: 200, originY: 100, unitX: 50, unitY: 50});
var p1 = b.createElement('point',[0,0], {name:'A',style:6});
var p2 = b.createElement('point',[2,-1], {name:'B',style:6});
var p3 = b.createElement('point',[-2,-3], {name:'C',style:6});
var p4 = b.createElement('point',[-1,-1], {name:'D',style:6});
var p5 = b.createElement('point',[3,1], {name:'E',style:6});
```

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

```
var poly = b.createElement('polygon',["A","B","C","D","E"]);
```

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

```
var poly = b.createElement('polygon',[p1,p2,p3,p4,p5]);
```

The result is the same: