Java2D:填充凸圆角多边形(QuadCurves)

发布于 2024-09-03 05:41:13 字数 945 浏览 13 评论 0原文

如果我有一个像这样的 QuadCurve (+ = node):

+         +
 \      ./
   +--⁻⁻

我用 Java 2D 填充它,结果是这样的: (x = colored)

+xxxxxxxxx+
 \xxxxxx./
   +--⁻⁻

但我想为另一侧着色:

+         +
x\      ./x
xxx +--⁻⁻xx
xxxxxxxxxxx

通过以我想要为另一侧着色的颜色在曲线周围绘制一个矩形,然后用背景颜色填充曲线来成功。

但这还不足以填充凸圆形(基于 QuadCurves)多边形。如果矩形的某些坐标(如我使用的技巧中所解释的)与多边形的其他部分重叠。这里有两张图片(绿色区域是我的多边形):

alt text http://img204 .imageshack.us/img204/7823/convexpolygon.png 替代文本 http: //img708.imageshack.us/img708/3669/convexpolygon2.png

所以,问题很简单:“如何为曲线的形状构建着色?”
但我认为答案并不简单...

任何建议都将非常非常感激。
提前致谢。

如果我没有得到答案,也许我会为这个问题悬赏

If I have a QuadCurve like this (+ = node):

+         +
 \      ./
   +--⁻⁻

And I fill it in Java 2D the result is something like this: (x = colored)

+xxxxxxxxx+
 \xxxxxx./
   +--⁻⁻

But I want to color the other side:

+         +
x\      ./x
xxx +--⁻⁻xx
xxxxxxxxxxx

This succeeds by drawing a rectangle around the curve in the color I want to color the other side and then fill the curve with the background color.

But this isn't good enough to fill a convex rounded (based on QuadCurves) polygon. In case of some coordinates for the rectangles (as explained in the trick I used) overlap other pieces of the polygon. Here are two images (the green area is my polygon):

alt text http://img204.imageshack.us/img204/7823/convexpolygon.png alt text http://img708.imageshack.us/img708/3669/convexpolygon2.png

So, the question is simple: "How can I color a shape build of curves?"
But to the answer will not be simple I think...

Any advice would be VERY VERY appreciated.
Thanks in advance.

Maybe I'm going to make a bounty for this question if I don't get an answer

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

顾铮苏瑾 2024-09-10 05:41:13

选择一个已知位于多边形内部的点。

了解“边界颜色”(在本例中为黑色)。

recurrsiveFill(Pixel p, Color fill, Color bound) {
    p.setColor(fill);
    if(p.left.color  != bound && p.left.color != fill) 
        recurrsiveFill(p.left , fill, bound);
    if(p.right.color != bound && p.right.color != fill) 
        recurrsiveFill(p.right, fill, bound);
    if(p.up.color    != boun d&& p.up.color    != fill) 
        recurrsiveFill(p.up,    fill, bound);
    if(p.down.color  != bound && p.down.color  != fill) 
        recurrsiveFill(p.down,  fill, bound);
}

您可以根据需要进行调整以满足您的特定需求。

这适用于完全有界形状的任何填充。您还需要合并特殊条件(例如图片的边缘)。

Pick a point known to be inside the Polygon.

Know the "boundary color" (in this case, black).

recurrsiveFill(Pixel p, Color fill, Color bound) {
    p.setColor(fill);
    if(p.left.color  != bound && p.left.color != fill) 
        recurrsiveFill(p.left , fill, bound);
    if(p.right.color != bound && p.right.color != fill) 
        recurrsiveFill(p.right, fill, bound);
    if(p.up.color    != boun d&& p.up.color    != fill) 
        recurrsiveFill(p.up,    fill, bound);
    if(p.down.color  != bound && p.down.color  != fill) 
        recurrsiveFill(p.down,  fill, bound);
}

You can adapt this as necessary to suit your specific needs.

This works for any fill for a completely bounded shape. You'll also want to incorporate special conditions (edges of the picture, for example).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文