0

I'm applying the scan-line algorithm to fill in a randomly generated continent-like shape. The main problem I'm having is when the line intersects a point that is a tip. I created some images to help visualize this.

https://i.stack.imgur.com/OlbI5.png

https://i.stack.imgur.com/RACF1.png

I basically need help figuring out how to differentiate if an intersection point is a "tip" or not. Like in the first image, since both are tips, I end up with a line in between them, even though the line is outside of the continent-shape.

  • 1
    What is the second image? What you are currently getting? – thatidiotguy Nov 05 '12 at 22:35
  • with the second image, I get a line drawn from the first blue point to the last blue point. So i get the interior part filled but the exterior segment before it is filled as well. – user1801501 Nov 05 '12 at 22:42
  • If your lines are just pixels, you're screwed. You have to flood-fill. If your lines are part of a polygon representation, then a single vertex in that polygon represents an intersection with two edges. Should cause no problem -- if the two edges are on the same side of the scanline, you treat it as two edges. Otherwise you treat it as one. – paddy Nov 05 '12 at 22:44
  • what do you mean by "on the same side of the scan line?" – user1801501 Nov 05 '12 at 22:48

1 Answers1

1

try checking to the immediate left and the right of the intersection. If they're both below the red line, than it's a tip.

That's the best i can do without knowing more about how the lines are defined.

  • the lines start from the top most point of the shape, and are one pixel thick. I draw a line from left to right sides of the image, and look at all of the intersection points. Then using those intersections, I draw a line to fill the interior. After that, I move one pixel down until repeat the same process until i reach the lowest point of the shape – user1801501 Nov 05 '12 at 22:44
  • @user1801501 well if the lines are defined pixel by pixel, than yeah, you'd have to look one pixel to the left and one pixel to the right. – Sam I am says Reinstate Monica Nov 05 '12 at 22:50