Skip to main content
Added a tiny bit of background to help with visualisation.
Source Link

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.

I can program, but have only recently started to learn graphics and the related math, so sorry for any ignorance here.

Imagine a top-down 2D game with a programmable robot that drives around and uses a laser range finder to get the distance to the nearest wall.

I'm using a DDA generator function that yields pixel coordinates, going from the robot, along a line in the direction it's facing.

The range finding function consumes the coordinates for one pixel at a time, checking each until one hits something. At that point, the function just returns the number of iterations it took (the number of pixels that were checked) as the distance. This avoids calculating the 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.

I'm working on a game with a programmable robot. It uses a laser range finder to get the distance to walls.

I'm using DDA to generate a line from the robot, going in the direction it is pointing, then checking each pixel along the line to see if it hits anything. At that point, the number of pixels checked so far is used as the range, to save having to calculate the proper length.

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.
added 58 characters in body
Source Link

I can program, but have only recently started to learn graphics and the related math, so sorry for any ignorance here.

Imagine a top-down 2D game with a programmable robot that drives around and uses a laser range finder to get the distance to the nearest wall.

I'm using DDA to draw a lineDDA generator function that yields pixel coordinates, going from the robot (in, along a line in the direction it's facing), then checking each point on the line till it hits something (or runs out of range).

WheneverThe range finding function consumes the linecoordinates for one pixel at a time, checking each until one hits something. At that point, the function just returns the number of iterations it took to get to that point (the number of pixels that were checked) as the distance. This avoids calculating the 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.

I can program, but have only recently started to learn graphics and the related math, so sorry for any ignorance here.

Imagine a top-down 2D game with a programmable robot that drives around and uses a laser range finder to get the distance to the nearest wall.

I'm using DDA to draw a line from the robot (in the direction it's facing), then checking each point on the line till it hits something (or runs out of range).

Whenever the line hits something, the function just returns the number of iterations it took to get to that point (the number of pixels that were checked) as the distance. This avoids calculating the 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.

I can program, but have only recently started to learn graphics and the related math, so sorry for any ignorance here.

Imagine a top-down 2D game with a programmable robot that drives around and uses a laser range finder to get the distance to the nearest wall.

I'm using a DDA generator function that yields pixel coordinates, going from the robot, along a line in the direction it's facing.

The range finding function consumes the coordinates for one pixel at a time, checking each until one hits something. At that point, the function just returns the number of iterations it took (the number of pixels that were checked) as the distance. This avoids calculating the 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.
Source Link

How different can the number of pixels in a straight line be to its real length?

I can program, but have only recently started to learn graphics and the related math, so sorry for any ignorance here.

Imagine a top-down 2D game with a programmable robot that drives around and uses a laser range finder to get the distance to the nearest wall.

I'm using DDA to draw a line from the robot (in the direction it's facing), then checking each point on the line till it hits something (or runs out of range).

Whenever the line hits something, the function just returns the number of iterations it took to get to that point (the number of pixels that were checked) as the distance. This avoids calculating the 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.