偏向4分的中点?
我试图了解我被赋予使用的一段源代码的基础知识。它有效,这已经被证明了。我只是想很好地理解它的原因,以便我可以自己做,或者可能扩展/扩展它。
相关代码查找 3D 空间中两条斜线之间最短线的中点。 这篇论文是我最接近的找到匹配的东西,但我仍然缺少一些概念步骤(而且我的线性代数技能已经落后了几十年)
在此应用中,P1、P2、P3 和 P4 是空间中的 3D(X、Y、Z)点。我们关心的线是 P1-P2 和 P3-P4。
该系统运行的语言不包含行列式函数,因此原始程序员编写了自己的语言。 VectMagn 是一个系统函数,它仅返回 3D 点值的范数(即 SQRT(X^2 + Y^2 + Z^2))。 Pow(i,j) 就像它看起来的那样,返回 i^j。
我最困惑的地方是 t 的大公式。根据我迄今为止的研究,我预计这两行都需要 转换为单位向量线,然后按照第一个 PDF 进行处理。但是 t 公式似乎一次性完成了所有这些工作,而我错过了中间步骤。显然,它是根据 Ps 1-4 上的各种矩阵数学创建两个 2x2 矩阵,然后将一个矩阵的行列式除以另一个矩阵。
如果我理解正确的话,t 是 PDF 中的 r1 和 r2,具体取决于点传递到 iv3DSkewLinePoint 的顺序。但我还没有找到任何论文或公式来解释这个特定算法为何/如何工作。到目前为止,我发现的所有内容都从单位向量线开始,并从那里继续前进。
! Returns the derterminant of a matrix
LOCAL FUNC num Det(num a,num b,num c,num d)
RETURN (a*d-c*b);
ENDFUNC
! Returns a point on a line (P1-P2) closest to a point on a skewed line (P3-P4)
FUNC pos iv3DSkewLinePoint(pos P1,pos P2,pos P3,pos P4)
VAR num x;
VAR num y;
VAR num z;
VAR num t;
t:=Det(DotProd(P3-P1,P2-P1),DotProd(P4-P3,P2-P1),DotProd(P3-P1,P4-P3),Pow(VectMagn(P4-P3),2))/Det(Pow(VectMagn(P2-P1),2),DotProd(P4-P3,P2-P1),DotProd(P2-P1,P4-P3),Pow(VectMagn(P4-P3),2));
x:=P1.x+(P2.x-P1.x)*t;
y:=P1.y+(P2.y-P1.y)*t;
z:=P1.z+(P2.z-P1.z)*t;
RETURN [x,y,z];
ENDFUNC
! Returns the closest point to two skewed lines in space
FUNC pos iv3DSkewLineMidpoint(pos P1,pos P2,pos P3,pos P4)
RETURN 0.5*(iv3DSkewLinePoint(P1,P2,P3,P4)+iv3DSkewLinePoint(P3,P4,P1,P2));
ENDFUNC
I'm trying to understand the basics underlying a piece of source code I was given to use. It works, this is proven. I'm just trying to wrap my head around the why of it well enough that I could do it myself, or possibly extend/expand upon it.
The code in question finds the midpoint of the shortest line between two skew lines in 3D space. This paper is the closest I've come to finding something that matches, but I'm still missing some conceptual steps (and my linear algebra skills are decades out of use)
In this application, P1, P2, P3, and P4 are 3D (X,Y,Z) points in space. The lines we're concerned with are P1-P2 and P3-P4.
The language this system runs on doesn't include a Determinant function, hence why the original programmer wrote their own. VectMagn is a system function that simply returns the Norm of a 3D point value (ie, SQRT(X^2 + Y^2 + Z^2)). Pow(i,j) is just what it looks like, returning i^j.
Where I'm most getting stuck is the large formula for t. Based on my research so far, I would expect that both lines would need to be converted into unit-vector lines, then processed as per the first PDF. But the t formula appears to be doing all of this in one jump, and I'm missing the intermediate steps. It's obviously creating two 2x2 matrices from various matrix math on Ps 1-4, then dividing the Determinant of one matrix by the other.
If I'm understanding this correctly, t is r1 and r2 from the PDF, depending on which order the Points were passed to iv3DSkewLinePoint. But I haven't yet found any papers or formulae that explain why/how this particular algorithm works. So far, everything I've found starts with unit-vector lines and moves on from there.
! Returns the derterminant of a matrix
LOCAL FUNC num Det(num a,num b,num c,num d)
RETURN (a*d-c*b);
ENDFUNC
! Returns a point on a line (P1-P2) closest to a point on a skewed line (P3-P4)
FUNC pos iv3DSkewLinePoint(pos P1,pos P2,pos P3,pos P4)
VAR num x;
VAR num y;
VAR num z;
VAR num t;
t:=Det(DotProd(P3-P1,P2-P1),DotProd(P4-P3,P2-P1),DotProd(P3-P1,P4-P3),Pow(VectMagn(P4-P3),2))/Det(Pow(VectMagn(P2-P1),2),DotProd(P4-P3,P2-P1),DotProd(P2-P1,P4-P3),Pow(VectMagn(P4-P3),2));
x:=P1.x+(P2.x-P1.x)*t;
y:=P1.y+(P2.y-P1.y)*t;
z:=P1.z+(P2.z-P1.z)*t;
RETURN [x,y,z];
ENDFUNC
! Returns the closest point to two skewed lines in space
FUNC pos iv3DSkewLineMidpoint(pos P1,pos P2,pos P3,pos P4)
RETURN 0.5*(iv3DSkewLinePoint(P1,P2,P3,P4)+iv3DSkewLinePoint(P3,P4,P1,P2));
ENDFUNC
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
3D 中两条斜线之间的最短线段必须垂直于两条斜线(垂直投影是最短的)。
因此,我们必须得到满足以下条件的两个点 A 和 B:
A 位于 P1..P2 线上,因此使用矢量表示法以参数形式表示:
B 位于 P3..P4 线上,因此以参数形式表示
矢量 AB 垂直到 P1P2,所以点积为零
向量 AB 垂直于 P3P4,因此点积为零
其他内容是向量代数计算,以找到
u
和v
参数(代码中 iv3DSkewLinePoint 中的t
)。我认为论文中带有点积的第一个表达式比末尾带有许多向量积的表达式更容易计算 - 注意 wiki方法需要唯一的向量乘积计算。
看起来
t
的公式很长,代表纸上的r1
公式,但它相当难以阅读。另外:
Paul Bourke 短文(含代码)
我的代码基于 D.Eberly (geometrictools.com) 的“计算机图形几何工具”一书
The shortest segment between two skew lines in 3D must be perpendicular to both (perpendicular projection is the shortest one).
So we have to get two points A and B that fulfill the next conditions:
A lies on P1..P2 line, so in parametric form using vector notation:
B lies on P3..P4 line, so in parametric form
vector AB is perpendicular to P1P2, so dot product is zero
vector AB is perpendicular to P3P4, so dot product is zero
Other stuff is vector algebra calculation to find
u
andv
parameters (t
in iv3DSkewLinePoint in your code).I think that first expressions in the paper with dot products are simpler to calculate, than expressions with many vector product at the end - note wiki approach requires the only vector product calculation.
Seems yout long formula for
t
representsr1
formula from paper, but it is rather hard readable.in addition:
Paul Bourke short article with codes
My code based on "Geometric Tools for Computer Graphics" book of D.Eberly (geometrictools.com)