Polygon : Java Glossary


The java.awt.Polygon class has a few surprises. Polygon.addpoint like an ArrayList automatically grows the xpoints and ypoints arrays if they become full. However, there is no constructor to suggest an initial size for these arrays. Npoints refers to how many actual data points you have not to the length of the xpoints and ypoints arrays.

The Polygon(xpoints,ypoints,npoints) constructor is not for giving it a hint how big to initialise the arrays. It is used when you already have an array of actual data points you want copied into your Polygon to get it started.

Graphics.drawPolygon and Graphics.fillPolygon don’t mind if a polygon is closed or not. They don’t seem to care if you define the points in clockwise or counter-clockwise order. I have written code part of the demonstration Screw package the generates regular polygons. Here is how to generate a regular polygon.

This page is posted
on the web at:


Optional Replicator mirror
of mindprod.com
on local hard disk J:

Canadian Mind Products
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

Your face IP:[]
You are visitor number