Get all pixel coordinates between 2 points

后端 未结 3 1299
我寻月下人不归
我寻月下人不归 2021-02-04 13:20

I want to get all the x,y coordinates between 2 given points, on a straight line. While this seems like such an easy task, I can\'t seem to get my head around it.

So, fo

3条回答
  •  花落未央
    2021-02-04 14:19

    Given the point A(10, 5) and B(15, 90) and C(x, y) in AB we have:

    (x - 10) / (y - 5) = (15 - 10) / (90 - 5)
    

    What you can do is to iterate from x=10 to x=15 and calculate the corresponding y. Since x and y are integers, some times you have to round the result (or skip it).

提交回复
热议问题