> 数学 >
怎样计算平面内两条线段的最短距离
平面内线段的位置是任意的,已知两条线段四个端点的坐标.最好不要角方程,通过程序可计算的
自己也找到了算法逻辑,贴出来服务大家吧,
AB and CD are line segments
Solving the above for r and s yields
r = ((Ay-Cy)(Dx-Cx)-(Ax-Cx)(Dy-Cy))/((Bx-Ax)(Dy-Cy)-(By-Ay)(Dx-Cx)) ------ (eqn 1)
s = ((Ay-Cy)(Bx-Ax)-(Ax-Cx)(By-Ay))/((Bx-Ax)(Dy-Cy)-(By-Ay)(Dx-Cx)) ------ (eqn 2)
Let Point be the position vector of the intersection point,then
Point=A+r(B-A) or
Px=Ax+r(Bx-Ax)
Py=Ay+r(By-Ay)
By examining the values of r & s,you can also determine some other
limiting conditions:
If 0
人气:457 ℃ 时间:2020-05-25 02:00:26
解答
Mathematica 版本的.
推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版