Math 在直线上寻找点
我知道线段的起点和终点。对于本例,假设线段的距离为5。现在我想知道距离终点3的点。你知道怎么用数学来做吗 起点(0,0) 终点(0,5) 如果你的点是Math 在直线上寻找点,math,opengl,linear-algebra,Math,Opengl,Linear Algebra,我知道线段的起点和终点。对于本例,假设线段的距离为5。现在我想知道距离终点3的点。你知道怎么用数学来做吗 起点(0,0) 终点(0,5) 如果你的点是(x1,y1)和(x2,y2),你想找到点(x3,y3),即距离点2的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 y
(x1,y1)
和(x2,y2)
,你想找到点(x3,y3)
,即距离点2的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
+1-经过数小时的努力,我终于想,“嘿,为什么不检查一下呢?”30秒后,我有了一个完全可行的解决方案。出于我的目的,我交换了x3,y3计算中的x和y,以便它表示从起点的距离。