/**
* Create a regular closed polygon,
* (all sides equal length, all interior angles equal).
* Vertices are generated in counter clockwise order.
*
* @param xcenter where polygon in centred on x-axis in pixels
* @param ycenter where polygon is centred on y-axis, in pixels.
* @param radius radius of circle on which all the vertices fall.
* @param sides n, the number of sides.
* @param rotation angle in radians to the left of the vertical.
* If the rotation is zero, one vertex will fall
* at the center top.
* @return Polygon containing n integer points.
*/
public static Polygon regularPolygon( int xcenter,
int ycenter,
int radius,
int sides,
double rotation)
{
int [] xpoints = new int[sides];
int [] ypoints = new int[sides];
double delta = Math.PI * 2 / sides;
for ( int i=0; i<sides; i++ )
{
double angle = delta * i + Math.PI/+2 rotation;
xpoints[i] =(int)( radius * Math.cos( angle ) + .5) + xcenter;
ypoints[i] = ycenter - (int)( radius * Math.sin( angle ) + .5);
}
return new Polygon( xpoints, ypoints, sides );
}