how to find a point in the path of a line

前端 未结 3 1496
甜味超标
甜味超标 2021-01-29 04:10

I\'ve got two points between which im drawing a line (x1,y1 and x2,y2) but i need to know the coordinates of x3,y3 which is gapSize<

3条回答
  •  星月不相逢
    2021-01-29 04:47

    Compute the distance between P1 and P2: d=sqrt( (y2-y1)^2 + (x2-x1)^2)

    Then x2 = (d*x1 + gapSize*x3) / (d+gapSize)

    So x3 = (x2 * (d+gapSize) - d*x1) / gapSize

    Similarly, y3 = (y2 * (d+gapSize) - d*y1) / gapSize

    Sorry for the math. I didn't try to code it but it sounds right. I hope this helps.

提交回复
热议问题