Szala
Szala

Reputation: 191

GeneralPath: What is winding?

What is winding? Yeah, i know, "read the description".

'A non-zero winding rule for determining the interior of a path.'

'An even-odd winding rule for determining the interior of a path.'

I can't understand what winding, 'non-zero' and 'even-odd' means here. Can someone explain that with other words? I can't see the difference in the screen.

    GeneralPath gen1 = new GeneralPath(GeneralPath.WIND_NON_ZERO);
    GeneralPath gen2 = new GeneralPath(GeneralPath.WIND_EVEN_ODD);

Upvotes: 1

Views: 2595

Answers (3)

lumpchen
lumpchen

Reputation: 355

In PDF specification, there are 2 firgures to describe Nonzero Winding Number Rule and Even-Odd Rule. enter image description here enter image description here

Upvotes: 4

Boo Radley
Boo Radley

Reputation: 682

As you discovered the Javadoc is not very helpful in this instance:

WIND_EVEN_ODD

public static final int WIND_EVEN_ODD

An even-odd winding rule for determining the interior of a path.

WIND_NON_ZERO

public static final int WIND_NON_ZERO

A non-zero winding rule for determining the interior of a path.

But the link @RC provided has a useful explanation.

There are two common methods for determining if any point is inside a geometric shape. The first, called the odd-even rule, is based on drawing a line (ray) from the point to be classified to any point well outside the shape. If the number of edge crossings is odd, the point is inside the shape; otherwise it is not. The second approach is termed the non-zero winding rule and likewise determines the number of edge crossings that occur for a ray drawn to a distant point. However, in the non-zero winding rule scheme, the left to right crossings add to the total number of crossing whereas the right to left crossing subtracts from the total number of crossings. If the sum of left to right and right to left crossing isn't equal to zero, the point is determined to be inside. Figure 3.3 shows an example of applying the two rules. Indeed the odd-even and non-zero winding rules give different answers for the ambiguous area labeled 1.

References

Upvotes: 2

Marc Wittmann
Marc Wittmann

Reputation: 2361

I think this one explains it pretty perfect

enter image description here

The even-odd rule yields the same results as the non-zero winding rule for simple shapes, but different results for more complex ones.

Another theoretical example can be found here (without code) Example

Upvotes: 2

Related Questions