Java2D: Fill a convex rounded polygon (QuadCurves)

Posted by Martijn Courteaux on Stack Overflow See other posts from Stack Overflow or by Martijn Courteaux
Published on 2010-05-28T20:41:26Z Indexed on 2010/05/28 21:12 UTC
Read the original article Hit count: 258

Filed under:
|
|
|
|

Hi,

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 alt text

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

© Stack Overflow or respective owner

Related posts about java

Related posts about shapes