Jump to content
  • Advertisement
Sign in to follow this  
Haytil

Recognizing Lines in Pixel Arrays

This topic is 3435 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I have a relatively simple problem that I wonder if there is an already-existent solution for: I have an array of 2D integer coordinates, representing pixels. The array in total represents an approximation of a curve. So when rendering the curve, I draw a line between the first coordinate and the second coordinate, then a line between the second and the third coordinate, and so forth. Because of the way I develop these curves, many of the coordinates are redundant. For example, the first, second, and third set of coordinates may all lie on the same line - so drawing a line between the first and second and then between the second and third would result in no visual difference than if I had simply drawn a line between the first and third. Because my line-drawing renderer is very slow, every redundant line I can remove would end up in a substantial time-saving (especially since many of the lines connect neighboring pixels). Because this array represents a curve, I cannot simply draw a line between the first and the final coordinate. What I need is to be able to run through the array and remove all redundancies. I'm sure with a bit of effort I could code up something that would be satisfactory, and if I have to, that's not a problem. But it seems like this is an algorithm that's likely been developed before - I just don't know the name. If anyone can point me to an algorithm that does what I require (run through a list of coordinates to remove redundant lines), than I would greatly appreciate it. Thank you.

Share this post


Link to post
Share on other sites
Advertisement
Have you tried the naive algorithm of just looking at adjacent line segments and "collapsing" (i.e. remove the middle point) them if the dot product between them is close to 1/-1 (i.e. they are almost parallel)?

For more involved solutions, I suggest googling for "line simplification".

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!