开发者

Java - filling an overlapping polygon

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, circ开发者_运维知识库ling 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.


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


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().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜