I can program, but have only recently started to learn graphics and the related math, so sorry for any ignorance here.
ImagineI'm working on a top-down 2D game with a programmable robot that drives around and. It uses a laser range finder to get the distance to the nearest wallwalls.
I'm using a DDA generator function that yields pixel coordinates, goingto generate a line from the robot, along a linegoing in the direction it's facing.
The range finding function consumes the coordinates for one pixel at a timeit is pointing, then checking each until onepixel along the line to see if it hits somethinganything. At that point, the function just returns the number of iterations it took (the number of pixels that were checked) so far is used as the distance. This avoids calculatingrange, to save having to calculate the proper length of the line properly, but how sketchy is this approach?.
If the line is horizontal or vertical, then there's no discrepancy, but how greatly does the number of pixels in a line differ from its real length in the worst case?
Notes:
- The length of the line is never just a few pixels, say always at least 50px.
- Longer lines obviously have larger discrepancies, but the question is really about relative differences.