gpt4 book ai didi

c# - 根据与该线相切的第三点在线上找到点

转载 作者:太空宇宙 更新时间:2023-11-03 15:17:04 25 4
gpt4 key购买 nike

找到从由两点定义的直线到一个点的距离得到了很好的回答,Shortest distance between a point and a line segment .在那个答案中 http://paulbourke.net/geometry/pointlineplane/说明了线 P1、P2 与点 P3 相切,显示了如何确定到该点的距离。这是一个 GPS 应用程序,所以线的航向已经确定,我不想使用点斜率公式或截取它的限制。

我想确定切线与 P1 P2 定义的 P3 的那条线相交的点。提前谢谢你。

编辑:

我有一个解决方案,但它有点麻烦,但也许不是,它确实有效:

1) Calculate distance to point by 2 point line to P3 but don't take abs value 
2) If distance < 0 then side = 1 else side = -1
3) dist = abs(distance)
4) rad2 = heading + PI/2 * side //tangent is always 90 degrees to line
5) sin rad2*dist + P3.x = point Q.x
6) cos rad2*dist + P3.y = point Q.y

无论点在哪一边似乎都有效

sketch

最佳答案

如果一条线由方程 A*x+B*y+C=0 已知,并且点 P 位于坐标为 ( P_x,P_y) 然后 在线 最接近 P 的点是

x = (A^2*P_y-A*B*P_x-B*C)/(A^2+B^2)
y = (B^2*P_x-A*B*P_y-A*C)/(A^2+B^2)

另外点P到直线的最小距离是

d = ABS(A*P_x+B*P_y+C)/SQRT(A^2+B^2)

编辑 1

通过两点 (x_1,y_1)(x_2,y_2) 的无限直线方程为

A*x+B*x+C=0
(y_1-y_2)*x + (x_2-x_1)*y + (x_1*y_2-x_2*y_1) = 0

编辑2

如果直线从点(Q_x,Q_y) 和方向(e_x,e_y) 给出,则方程系数为

A = -e_y
B = e_x
C = Q_x*e_y - Q_y*e_x

关于c# - 根据与该线相切的第三点在线上找到点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38704246/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com