我知道线段上的起点和终点。对于此示例,线段的距离为5。现在,我想知道与终点的距离为3的点。知道如何用数学做到这一点吗?
起点(0,0)
终点(0,5)
我想找到的点(0,2)
最佳答案
如果您的点是(x1, y1)
和(x2, y2)
,并且您想查找距离点2距离(x3, y3)
单位的点n
:
d = sqrt((x2-x1)^2 + (y2 - y1)^2) #distance
r = n / d #segment ratio
x3 = r * x2 + (1 - r) * x1 #find point that divides the segment
y3 = r * y2 + (1 - r) * y1 #into the ratio (1-r):r