计算点到线段和线段到线段的平均距离 [英] Compute average distance from point to line segment and line segment to line segment

查看:248
本文介绍了计算点到线段和线段到线段的平均距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种算法来计算3D中点与线段之间的平均距离。因此给定表示线段AB和第三点C(x3,y3,z3)的两个点A(x1,y1,z1)和B(x2,y2,z2),AB上每个点之间的平均距离是多少到点C?



我也对两条线段之间的平均距离感兴趣。因此,给定段AB和CD,从AB上每个点到CD上最近点的平均距离是多少?



我没有对网络搜索有任何好运我已经尝试了,所以有任何建议,将不胜感激。



谢谢。

如果你的意思是我认为你的意思是平均(和距离,即dreeves提到的L2规范),我认为这个过程应该用于寻找平均值点与线段之间的距离。你需要一个函数点(A,B),它取两个向量的点积。

<$ p $ (点)A,B,C
K1 =点(AC,AC)
K2 = 2 *点(BA,AC)
K3 =点(BA,BA)
L1 = sqrt(K3 *(K1 + K2 + K3))
L2 = sqrt(K3 * K1)
N = 4 * K3 * 2 * K2 *(L1-L2)+(K2 * K2-4 * K1 * K3)* log((K2 + 2 * L2)/(2 * K3 + K2 + 2 * L1))
D = N /(8 * K3 ^ 1.5)

假设我正确地转录了所有内容, D 将是平均距离。



这基本上只是伪代码,用于评估Mathematica中积分的结果。这可能有一些简洁的计算捷径,但如果有的话,我不知道它。 (除非有一个,我会质疑你需要做多少计算)



如果你想找到距离最近点的平均距离线段CD到AB上的所有点,在大多数情况下,最近的点将是C或D,因此您可以只检查这两者以查看哪个更接近(可能使用其他答案中引用的某个最小距离计算)。唯一的例外是当CD和AB平行时,你可以从一个到另一个运行一个垂直线,在这种情况下,你必须更精确地定义你的需求。



如果你想找到CD上所有点与AB上所有点之间的平均距离......它可以用双积分完成,但我不寒而栗,想想结果公式会是多么复杂。


I'm searching for an algorithm to calculate the average distance between a point and a line segment in 3D. So given two points A(x1, y1, z1) and B(x2, y2, z2) that represent line segment AB, and a third point C(x3, y3, z3), what is the average distance between each point on AB to point C?

I'm also interested in the average distance between two line segments. So given segment AB and CD, what is the average distance from each point on AB to the closest point on CD?

I haven't had any luck with the web searches I've tried, so any suggestions would be appreciated.

Thanks.

解决方案

If you mean what I think you mean by "average" (and "distance," i.e. the L2 norm mentioned by dreeves), here's a procedure that I think should work for finding the average distance between a point and a line segment. You'll need a function dot(A,B) which takes the dot product of two vectors.

// given vectors (points) A, B, C
K1 = dot(A-C,A-C)
K2 = 2*dot(B-A,A-C)
K3 = dot(B-A,B-A)
L1 = sqrt(K3*(K1+K2+K3))
L2 = sqrt(K3*K1)
N = 4*K3*L1 + 2*K2*(L1-L2) + (K2*K2-4*K1*K3)*log((K2+2*L2)/(2*K3+K2+2*L1))
D = N / (8*K3^1.5)

Assuming I've transcribed everything correctly, D will then be the average distance.

This is basically just pseudocode for evaluating the result of an integral that I did in Mathematica. There may be some neat computational shortcut for this but if there is, I don't know it. (And unless there is one, I'd question how much you really need to do this computation)

If you want to find the average distance from the closest point on a line segment CD to all points on AB, in most cases the closest point will be either C or D so you can just check both of those to see which is closer (probably using some minimum-distance calculation as referenced in other answers). The only exception is when CD and AB are parallel and you could run a perpendicular from one to the other, in which case you'd have to define your requirements more precisely.

If you wanted to find the average distance between all points on CD and all points on AB... it could be done with a double integral, though I shudder to think how complicated the resulting formula would be.

这篇关于计算点到线段和线段到线段的平均距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆