# Difference between revisions of "Polygon"

From JSXGraph Wiki

A WASSERMANN (talk | contribs) |
|||

Line 2: | Line 2: | ||

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

<source lang="javascript"> | <source lang="javascript"> | ||

− | var | + | var b1 = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-4, 2, 6, -4]}); |

− | var p1 = | + | var p1 = b1.create('point',[0,0], {name:'X',size:4}); |

− | var p2 = | + | var p2 = b1.create('point',[2,-1], {name:'B',size:4}); |

− | var p3 = | + | var p3 = b1.create('point',[-2,-3], {name:'C',size:4}); |

− | var p4 = | + | var p4 = b1.create('point',[-1,-1], {name:'D',size:4}); |

− | var p5 = | + | var p5 = b1.create('point',[3,1], {name:'E',size:4}); |

</source> | </source> | ||

Note that the "style" option is optional as is the parameter "name". | Note that the "style" option is optional as is the parameter "name". | ||

Next we create a polygon through these five points "A" to "E". | Next we create a polygon through these five points "A" to "E". | ||

<source lang="javascript"> | <source lang="javascript"> | ||

− | var poly = b. | + | var poly = b.create('polygon',["X","B","C","D","E"]); |

</source> | </source> | ||

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

Line 19: | Line 19: | ||

</source> | </source> | ||

The result is the same: | The result is the same: | ||

− | < | + | <jsxgraph box="jxgbox" width="500" height="300"> |

− | + | 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 b1 = JXG.JSXGraph.initBoard('jxgbox', { | + | var p4 = b1.create('point',[-1,-1], {name:'D',size:4}); |

− | var p1 = b1. | + | var p5 = b1.create('point',[3,1], {name:'E',size:4}); |

− | var p2 = b1. | ||

− | var p3 = b1. | ||

− | var p4 = b1. | ||

− | var p5 = b1. | ||

− | |||

− | |||

− | |||

− | |||

+ | var poly = b1.create('polygon',[p1,p2,p3,p4,p5]); | ||

+ | </jsxgraph> | ||

[[Category:Examples]] | [[Category:Examples]] |

## Revision as of 12:18, 8 June 2011

## 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 "style" option is optional as is the parameter "name". Next we create a polygon through these five points "A" to "E".

```
var poly = b.create('polygon',["X","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: