I have path from Bresenham line algorithm, example for A->B vector:

enter image description here

Path is [(0,5), (0,4), (1,4), (1,3), (1,2), (1,1), (2,1), (2,0)]. Considering A height is 10 meters, B height is 5 meters and a tree at position 1,1 is 5,5 meters:

enter image description here

How to know if point B is visible from point A ? My real question is: How to know the A->B vector height when it is "above" specific position, so here 1,1 ?

  • 2
    \$\begingroup\$ With regard to your use of Bresenham here, can you define in a bit more detail what criteria we should use to determine visibility? Say the Bresenham algorithm draws two vertically stacked pixels on this particular column. Have we blocked visibility if we cover just one of the two pixels? Or do we need to cover both to block the line? (ie. does the green dot at (1, 1) in the diagram above block the ray? Or do we need an occluder at (1, 2) or (2, 1)? \$\endgroup\$ – DMGregory Nov 28 '17 at 17:16
  • \$\begingroup\$ I closed the question on math exchange. Thanks for rules remind. @DMGregory Yes visibility blocked if just one of them is "to high". For simplify the question can be: Does exist a coordonate (taking it's height) on vector (in real, on Bresenham line) who block the vector. \$\endgroup\$ – bux Nov 29 '17 at 13:57

You can get it using linear interpolation.

Basically, the y coordinate of the point on the AB vector at a specific x coordinate is:

$$y = \vec A_y + (\vec B_y - \vec A_y)\space \cdot\space\frac{ x}{\vec B_x - \vec A_x}$$

If you need the tile height, then just floor the value


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.