在一条线上找到一个点 [英] Finding a point on a line
本文介绍了在一条线上找到一个点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道线段上的起点和终点.对于此示例,线段的距离为5.现在,我想知道与终点的距离为3的点.知道如何使用数学方法吗?
I know the start and end points on a line segment. For this example say that the line segment has a distance of 5. Now I want to know the point that has a distance of three away from the end point. Any idea how to do this with math?
起点(0,0) 终点(0,5)
Start Point (0,0) End Point (0,5)
我想找到的点(0,2)
Point I want to find (0,2)
推荐答案
如果您的点是(x1, y1)
和(x2, y2)
,并且您想查找与点2距离n
单位的点(x3, y3)
.
If your points are (x1, y1)
and (x2, y2)
, and you want to find the point (x3, y3)
that is n
units away from point 2:
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
这篇关于在一条线上找到一个点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文