问题描述
如何找到既给定(一条线上的2个点)又给定(从第三点到第一点的距离)的第三点?"语言:Visual Basic(2012)
"How to find a third point given both (2 points on a line) and (distance from third point to first point)?"Language: Visual Basic (2012)
第三个点与第二个点在同一条线上,并且可以更靠近第一个点,也可以更靠近第二个点.这是一个可以同时处理这两个功能的函数(来自数据数组).
The third point is on the same line as the second, and may be either closer to the first point or it may be closer to the second. This is a function that will handle both (from arrays of data).
奇怪的是,我似乎无法理解这个问题的距离部分.在阅读了许多其他关于从其他点寻找点的问题之后,我找不到足够清晰的东西使我能够进行反向工程以包含距离参数.
Strangely I cannot seem to grasp the distance part of this question. Over reading many other questions on finding points from other points, I am unable to find anything clear enough for me to be able to reverse engineer to include a parameter for distance.
我需要能够使用距离找到一个点.我正在编写的函数基本上是一种更高级的形式:
I need to be able to use distance to find a point. The function I am writing is basically a much more advanced form of:
Function GetThirdPoint(CenterPoint As Point, SecondPoint As Point, Range As Integer)
Return [Equations here] 'Return third point
End Function
推荐答案
让我们的第一个点坐标为P1 =(x1,y1),第二个点P2 =(x2,y2).
那么P1P2向量的长度是(如果可用,请使用Math.Hypot
函数)
Let's first point coordinates are P1=(x1,y1), second point P2=(x2,y2).
Then length of P1P2 vector is (use Math.Hypot
function if available)
Len = Sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
归一化(单位长度)方向向量为
Normalized (unit-length) direction vector is
dx = (x2-x1) / Len
dy = (y2-y1) / Len
当P1P3和P1P2向量具有相同方向时的P3坐标:
P3 coordinates for case when P1P3 and P1P2 vectors have the same direction:
x3 = x1 + Distance * dx
y3 = y1 + Distance * dy
反方向:
x3 = x1 - Distance * dx
y3 = y1 - Distance * dy
这篇关于如何在给定(一条线上的2个点)和(从第三个点到第一个点的距离)的同时找到第三个点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!