views:

68

answers:

1

I have images which have line segments, rays etc. I am representing these line segments using Bresenham algorithm (means whatever coordinates I get using this algorithm between two points). Now I want to do operations such as finding intersection point between two line segments, finding the projection of one vector onto other etc... The problem is I am not working in continuous space. The line segments are being approximated using Bresenham algorithm.

So I want suggestions on what are the best and most efficient ways to do this? A link to C++ library or implementation would also be good enough. Please suggest some books also which deal with such problems.

+1  A: 

Bresenham is just a way to rasterise a geometric entity, and is used to avoid per-pixel floating-point operations. There's nothing stopping you from reverting to analytic geometry to find intersections.

Marcelo Cantos
Ya I understand that but say I want to find the intersection between two lines. I will find the point by normal geometry but to get the actual point, I will round up and round down and search for it whether it is one of the coordinates approximated by bresenham method. I know how to do it by brute force. I just want some ideas on efficient algorithms.
avd
I don't remember the specifics, but I am pretty sure it is possible to analytically find the exact pixel at which they cross. You just have to be careful with how you round and what you consider the starting point (the center of the pixel, I think). Also note that the two lines may not touch at all, even if they cross.
Marcelo Cantos