tags:

views:

30

answers:

2

I'm trying to draw a 5 point star in AWT. Each point in the 2d grid is 72 degrees apart - so I thought I could draw the polygon using only 5 points by ordering the points 144 degrees apart, so the polygon gets fed the points in order 1,3,5,2,4

Unfortunately, this involves a lot of intersecting lines, and the end result is that there are 5 triangles with my desired colour, circling a pentagon that has not been coloured.

Looking through, it has something to do with an even-odd rule, that intersecting points will not be filled.

I need my star to be drawn dynamically, and using the specific shape described (for scaling and such). If I manually plot the points where it intersects, I get some human error in my star's shape.

Is there any way to just turn this feature off, or failing that, is there a way to get the polygon to return an array of x[] and y[] where lines intersect so I can just draw another one inside it?

Thanks.

A: 

Draw it with ten points, 36 degrees apart, at two alternating radii.

relet
I mentioned that in my original post - If I manually plot the points where it intersects, I get some human error in my star's shape. The second set of points seem to have a radius of approximately 1/3 the radius of the peaks, but I don't know exactly how much it is or I'd have done this.
Brian
A: 

Establish the 10-point Polygon in cartesian coordinates, as suggested by relet and as shown in this example. Note how the coordinate system is centered on the origin for convenience in rotating, scaling and translating. Because Polygon implements the Shape interface, the createTransformedShape() method of AffineTransform may be applied. A more advanced shape library may be found here.

Is there a way to get the polygon to return an array of x[] and y[] where lines intersect?

Although typically unnecessary, you can examine the component coordinates using a Shape's PathIterator. I found it instructive to examine the coordinates before and after invoking createTransformedShape().

trashgod