2 Replies Latest reply: Nov 26, 2012 8:03 AM by StanislavL RSS


      I have few closed java2D polygons say (7 or 8 Nos.) and each polygon lies within the other. For Example in case of 8 polygons(2 is inside 1, 3 is inside 2, 4 is inside 3 , 5 is inside 4 so on and so forth).

      i want to fill the difference of (1st and 2nd polygons), (3rd and 4th polygon), (5th and 6th polygon) and (7th and 8th polygon) with same color. ---- Case -1

      And also

      the difference of (2nd and 3rd polygons), (4th and 5th polygon) and (6th and 7th polygon) with same color. ------Case -2

      The color of Case-1 and Case-2 must not be same.

      If any one is having any idea, please share.

      Thanks in advance, Best Regards
        • 1. Re: Java2D
          You need to find the resulting Polygon and fill that.

          Maby so:
          <ul><li>Find center point of all Polygons (or the current 2 if you do sequientially)
          <li>find all points where Polygon lines cross.
          <li>For all the point you have no check if the line between the current point and the center crosses any existing line. <ul><li>yes: dismiss point. <li>no: add poin to resulting polygon</ul></ul>
          This does only apply to convex polygons.

          • 2. Re: Java2D
            Use Area class. Pass the Polygons in constructor (public Area(Shape s)).

            Area has methods
            public void subtract(Area rhs)
            public void intersect(Area rhs)
            public void add(Area rhs)
            So you can build any Area combining areas of the polygons.