且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在给定(一条线上的2个点)和(从第三个点到第一个点的距离)的同时找到第三个点

更新时间:2023-02-06 19:24:03

让我们的第一个点坐标为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