在直线上找一个点 [英] Finding a point on a line

查看:29
本文介绍了在直线上找一个点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道线段上的起点和终点.对于此示例,假设线段的距离为 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)

推荐答案

如果你的点是 (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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆