Mel*_*Mel 9 opengl math linear-algebra
我知道线段上的起点和终点.对于此示例,假设线段的距离为5.现在我想知道距终点距离为3的点.知道如何用数学做这个吗?
起点(0,0)终点(0,5)
点我想找(0,2)
Art*_*ius 28
如果您的积分是(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
Run Code Online (Sandbox Code Playgroud)