计算 3d 中线段之间的垂直距离和角距离

发布于 2024-10-20 20:20:00 字数 303 浏览 2 评论 0原文

我正在致力于用 C++ 实现聚类算法。具体来说,这个算法: http://www.cs.uiuc.edu/~ hanj/pdf/sigmod07_jglee.pdf

在算法中的某一点(第 3.2 p4-5 节),我要计算两条线段之间的垂直距离和角度距离(d┴ 和 dθ):p1 到 p2,p1 到p3。

我已经有一段时间没有上数学课了,我对这些实际上的概念以及如何计算它们有点动摇。有人可以帮忙吗?

I am working on implementing a clustering algorithm in C++. Specifically, this algorithm: http://www.cs.uiuc.edu/~hanj/pdf/sigmod07_jglee.pdf

At one point in the algorithm (sec 3.2 p4-5), I am to calculate perpendicular and angular distance (d┴ and dθ) between two line segments: p1 to p2, p1 to p3.

It has been a while since I had a math class, I am kinda shaky on what these actually are conceptually and how to calculate them. Can anyone help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心意如水 2024-10-27 20:20:00

要获取点 Q 到由两点 P_1P_2 定义的直线的垂直距离,请计算:

d = DOT(Q, CROSS(P_1, P_2) )/MAG(P_2 - P_1)

其中 DOT 是点积,CROSS 是向量叉积,MAG 是幅度 (sqrt(X*X+Y*Y+..)< /code>)

使用图 5。您计算 d_1sj 到直线 (si->ei) 的距离以及 d_2ej 到同一直线的距离。

我将基于三个点建立一个坐标系,其中两个(P_1P_2)表示一条线,第三个Q表示起点或终点其他线段的末端。坐标系的三个轴可以这样定义:

e = UNIT(P_2 - P_1)      // axis along the line from P_1 to P_2
k = UNIT( CROSS(e, Q) )  // axis normal to plane defined by  P_1, P_2, Q
n = UNIT( CROSS(k, e) )  // axis normal to line towards Q

其中UNIT() 是返回单位向量(幅度=1)的函数。

然后,您可以使用简单的点积确定所有投影长度。因此,考虑图 5 中的线 si-ei 和点 sj,长度为:

(l || 1) = DOT(e, sj-si);
(l |_ 1) = DOT(n, sj-si);
ps = si + e * (l || 1)      //projected point

并且在第二段 ej 的末尾,需要计算新的坐标轴(e,k,n)

(l || 2) = DOT(e, ei-ej);
(l |_ 1) = DOT(n, ej-ei);
pe = ei - e * (l || 1)      //projected point

最终角度距离为

(d th)  = ATAN( ((l |_ 2)-(L |_ 1))/MAG(pe-ps) )

PS。您可能想将其发布在 Math.SO 上,在那里您可以获得更好的答案。

To get the perpendicular distance of a point Q to a line defined by two points P_1 and P_2 calculate this:

d = DOT(Q, CROSS(P_1, P_2) )/MAG(P_2 - P_1)

where DOT is the dot product, CROSS is the vector cross product, and MAG is the magnitude (sqrt(X*X+Y*Y+..))

Using Fig 5. You calculate d_1 the distance from sj to line (si->ei) and d_2 the distance from ej to the same line.

I would establish a coordinate system based on three points, two (P_1, P_2) for a line and the third Q for either the start or the end of the other line segment. The three axis of the coordinate system can be defined as such:

e = UNIT(P_2 - P_1)      // axis along the line from P_1 to P_2
k = UNIT( CROSS(e, Q) )  // axis normal to plane defined by  P_1, P_2, Q
n = UNIT( CROSS(k, e) )  // axis normal to line towards Q

where UNIT() is function to return a unit vector (with magnitude=1).

Then you can establish all your projected lengths with simple dot products. So considering the line si-ei and the point sj in Fig 5, the lengths are:

(l || 1) = DOT(e, sj-si);
(l |_ 1) = DOT(n, sj-si);
ps = si + e * (l || 1)      //projected point

And with the end of the second segment ej, new coordinate axes (e,k,n) need to be computed

(l || 2) = DOT(e, ei-ej);
(l |_ 1) = DOT(n, ej-ei);
pe = ei - e * (l || 1)      //projected point

Eventually the angle distance is

(d th)  = ATAN( ((l |_ 2)-(L |_ 1))/MAG(pe-ps) )

PS. You might want to post this at Math.SO where you can get better answers.

゛时过境迁 2024-10-27 20:20:00

看第 3 页的图 5。它画出了 d┴ 和 dθ 是什么。

编辑:“莱默平均值”是使用 Lp-space 约定定义的。因此,在 3 维中,您将使用 p = 3。假设两个起点之间的(欧几里德)距离为 d1,两端之间的距离为 d2。然后d┴(L1, L2) = (d1^3 + d2^3) / (d1^2 + d2^2)

要查找两个向量之间的角度,您可以使用它们的点积。范数(表示为 ||x||)的计算 像这样

Look at figure 5 on page 3. It draws out what d┴ and dθ are.

EDIT: The "Lehmer mean" is defined using Lp-space conventions. So in 3 dimensions, you would use p = 3. Let's say that the (Euclidean) distance between the two start points is d1, and between the ends is d2. Then d┴(L1, L2) = (d1^3 + d2^3) / (d1^2 + d2^2).

To find the angle between two vectors, you can use their dot product. The norm (denoted ||x||) is computed like this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文