问题描述
我想计算与给定点垂直的给定线上的一个点.
I want to calculate a point on a given line that is perpendicular from a given point.
我有一条线段 AB,线段外有一个点 C.我想计算 AB 上的点 D,使得 CD 垂直于 AB.
I have a line segment AB and have a point C outside line segment. I want to calculate a point D on AB such that CD is perpendicular to AB.
我必须找到 D 点.
它非常类似于这个,但我想要还要考虑 Z 坐标,因为它在 3D 空间中无法正确显示.
It quite similar to this, but I want to consider to Z coordinate also as it does not show up correctly in 3D space.
推荐答案
证明:D点在垂直于AB的一条CD线上,当然D属于AB.写出两个向量CD.AB = 0的点积,将D属于AB的事实表示为D=A+t(B-A).
Proof:Point D is on a line CD perpendicular to AB, and of course D belongs to AB.Write down the Dot product of the two vectors CD.AB = 0, and express the fact D belongs to AB as D=A+t(B-A).
我们最终得到 3 个等式:
We end up with 3 equations:
Dx=Ax+t(Bx-Ax)
Dy=Ay+t(By-Ay)
(Dx-Cx)(Bx-Ax)+(Dy-Cy)(By-Ay)=0
在第三个方程中代入前两个方程给出:
Subtitute the first two equations in the third one gives:
(Ax+t(Bx-Ax)-Cx)(Bx-Ax)+(Ay+t(By-Ay)-Cy)(By-Ay)=0
分布求解 t 给出:
(Ax-Cx)(Bx-Ax)+t(Bx-Ax)(Bx-Ax)+(Ay-Cy)(By-Ay)+t(By-Ay)(By-Ay)=0
给出:
t= -[(Ax-Cx)(Bx-Ax)+(Ay-Cy)(By-Ay)]/[(Bx-Ax)^2+(By-Ay)^2]
去掉负号:
t=[(Cx-Ax)(Bx-Ax)+(Cy-Ay)(By-Ay)]/[(Bx-Ax)^2+(By-Ay)^2]
一旦你有了 t,你就可以从前两个方程中找出 D 的坐标.
Once you have t, you can figure out the coordinates for D from the first two equations.
Dx=Ax+t(Bx-Ax)
Dy=Ay+t(By-Ay)
这篇关于从给定点垂直于线段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!