Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 966919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:14:08+00:00 2026-05-16T02:14:08+00:00

I am working with drawing polygons based on a given line. I have the

  • 0

I am working with drawing polygons based on a given line. I have the logic working out well except in cases where it appears that the polygon intersects itself. However, it doesn’t seem to be 100% consistent, nor does it make sense based on what I’m reading. Below are two images created using the same code. The yellow polygons are the ones I’m concerned with.

Image: http://i31.tinypic.com/24cxxlf.png

I want every case to work like the first case (where the empty area “wrapped” by the polygon is not filled in).

These images are produced by this code:

BufferedImage drawingImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = drawingImage.createGraphics();
Polygon polygon = new Polygon(parsedPoints[0], parsedPoints[1], parsedPoints[0].length);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
g.setColor(drawingColor);
g.fillPolygon(polygon);
float[] scales = {1f, 1f, 1f, 0.7f};
float[] offsets = new float[4];
RescaleOp rop = new RescaleOp(scales, offsets, null);
graphics.drawImage(drawingImage, rop, 0, 0);
graphics.setStroke(new BasicStroke(2));
graphics.setColor(drawingColor);
graphics.drawPolygon(polygon);

(I’m filling the polygon applying a rescale to get some transparency to the fill, and then drawing the border without transparency.)

According to the Java documentation for the Graphics.fillPolygon method:

The area inside the polygon is defined
using an even-odd fill rule, also
known as the alternating rule.

If I understand that correctly, then in both cases a pixel contained within the area “wrapped” by the thick polygon would cross exactly two paths, so it would be considered “outside” the polygon.

So my questions are: (a) am I understanding the even-odd fill rule and (b) is there a way in Java to make the second image work more like the first?

Any thoughts on this would be greatly appreciated.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T02:14:09+00:00Added an answer on May 16, 2026 at 2:14 am
    1. The rule applies per polygon. Java doesn’t care about the polygon you drew even one statement ago.
    2. You seem to be misunderstanding the even-odd rule a bit. The practical version of the rule goes a bit like this…for each ‘y’ coordinate the polygon crosses, there’s an ordered list of all the x coordinates where it crosses. The ‘inside’ of the polygon is the sections from each even-numbered index (0, 2, 4…) to the next odd-numbered index.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.