简体   繁体   English

Java-填充重叠的多边形

[英]Java - filling an overlapping polygon

I'm trying to draw a 5 point star in AWT. 我正在尝试在AWT中绘制5点星。 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 2d网格中的每个点相隔72度-因此,我认为可以通过将点之间相距144度进行排序而仅使用5个点来绘制多边形,因此多边形以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. 不幸的是,这涉及许多相交的线,最终结果是有5个三角形具有我想要的颜色,并围绕一个未着色的五边形。

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? 有没有办法关闭此功能,否则,是否有办法使多边形返回直线相交的x []和y []数组,因此我可以在其中绘制另一个?

Thanks. 谢谢。

用两个交替半径的十个点(相隔36度)绘制它。

Establish the 10-point Polygon in cartesian coordinates, as suggested by relet and as shown in this example . 按照relet的建议并如本示例所示,在笛卡尔坐标中建立10点Polygon 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. 由于Polygon实现了Shape接口,因此可以应用AffineTransformcreateTransformedShape()方法。 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? 有没有办法让多边形返回线相交的x[]y[]数组?

Although typically unnecessary, you can examine the component coordinates using a Shape's PathIterator . 尽管通常不需要,但是您可以使用Shape's PathIterator检查组件坐标。 I found it instructive to examine the coordinates before and after invoking createTransformedShape() . 我发现在调用createTransformedShape()之前和之后检查坐标createTransformedShape()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM