how to find a point in the path of a line

前端 未结 3 1465
甜味超标
甜味超标 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

    You can simply calculate the angle in radians as

    double rads = atan2(y2 - y1, x2 - x1);
    

    Then you get the coordinates as follows:

    double x3 = x2 + gapSize * cos(rads);
    double y3 = y2 + gapSize * sin(rads);
    

    Is this what you meant?

提交回复
热议问题