HiveBrain v1.2.0
Get Started
← Back to all entries
snippetMinor

How to handle horizontal lines in the Polyfill Algorithm?

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
polyfillthehandlealgorithmhorizontalhowlines

Problem

When I look at polyfill algorithm tutorials/articles or examples, nothing mentioned about how to handle horizontal lines. Does anyone have any idea how horizontal lines should be handled?

For instance, consider the following image:

For intersection I wrote if the line on the scan line count it as 1 point, even I count as 2 point or no point, wont help. Any idea how should I handle the horizontal line?

Edit: here a complex example of horizontal line intersection, let's take a look at line 3:

Alright, if we take a look at next point and previous point of the intersection of both end of horizontal line, if those point are in same side, means I can count them in or out, doesn't effect the whole calculation.

But if they are are opposite side, I have to count them in and count one side extra.

What do I mean?

Take InterS1 and InterS2 as an example, so when I get this I have count that horizontal line as 3 points:

point1 = InterS1
point2 = InterS2
point3 = InterS2


Why I need to do that?

  • When next point and previous point are in different direction, is letting us know that our intersection line crossing outside and passing through inside of shape.



  • Also because line can be created when there is start point and end point, so I need to have even number to draw lines.



So now I have no idea base on what I need to add the extra point to one side.

Do I make sense?

Solution

See Polygon Filling. It gives one method to deal with edges parallel to scanline. It says that it is imperfect, but you can ignore the horizontal edges. Other solution is to take either left or right endpoint of horizontal edge (any one point only). Yet another solution is to take right or left endpoint depending on the situation, so that whole edge is filled.

If you ignore horizontal lines you should get something like the following:

Context

StackExchange Computer Science Q#53266, answer score: 2

Revisions (0)

No revisions yet.