计算 3D(或 n-D)质心的最佳方法是什么? [英] What's the best way to calculate a 3D (or n-D) centroid?

查看:24
本文介绍了计算 3D(或 n-D)质心的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为工作项目的一部分,我必须计算 3D 空间中一组点的质心.现在我正在以一种看似简单但很幼稚的方式进行操作——取每组点的平均值,如下所示:

As part of a project at work I have to calculate the centroid of a set of points in 3D space. Right now I'm doing it in a way that seems simple but naive -- by taking the average of each set of points, as in:

centroid = average(x), average(y), average(z)

其中 xyz 是浮点数数组.我似乎记得有一种方法可以获得更准确的质心,但我还没有找到一个简单的算法来这样做.任何人有任何想法或建议?我为此使用 Python,但我可以改编其他语言的示例.

where x, y and z are arrays of floating-point numbers. I seem to recall that there is a way to get a more accurate centroid, but I haven't found a simple algorithm for doing so. Anyone have any ideas or suggestions? I'm using Python for this, but I can adapt examples from other languages.

推荐答案

与这里的常见说法相反,定义(和计算)点云中心的方法有多种.您已经提出了第一个也是最常见的解决方案,我不会争辩说这有什么问题:

Contrary to the common refrain here, there are different ways to define (and calculate) a center of a point cloud. The first and most common solution has been suggested by you already and I will not argue that there is anything wrong with this:

centroid = average(x),average(y),average(z)

这里的问题"是它会根据点的分布扭曲"您的中心点.例如,如果您假设所有点都在立方体或其他几何形状内,但其中大部分恰好位于上半部分,那么您的中心点也会向该方向移动.

The "problem" here is that it will "distort" your center-point depending on the distribution of your points. If, for example, you assume that all your points are within a cubic box or some other geometric shape, but most of them happen to be placed in the upper half, your center-point will also shift in that direction.

作为替代方案,您可以在每个维度中使用数学中间值(极值的平均值)来避免这种情况:

As an alternative you could use the mathematical middle (the mean of the extrema) in each dimension to avoid this:

middle = middle(x), middle(y), middle(z)

当您不太关心点的数量,但更关心全局边界框时,您可以使用它,因为这就是 - 围绕您的点的边界框的中心.

You can use this when you don't care much about the number of points, but more about the global bounding box, because that's all this is - the center of the bounding box around your points.

最后,您还可以在每个维度中使用 median(中间的元素):

Lastly, you could also use the median (the element in the middle) in each dimension:

中位数 = 中位数(x)、中位数(y)、中位数(z)

现在这将有点与middle相反,实际上可以帮助您忽略点云中的异常值,并根据您的点的分布找到一个中心点.

Now this will sort of do the opposite to the middle and actually help you ignore outliers in your point cloud and find a centerpoint based on the distribution of your points.

找到好"中心点的更可靠的方法可能是忽略每个维度的顶部和底部 10%,然后计算 averagemedian.如您所见,您可以用不同的方式定义中心点.下面我将向您展示包含这些建议的 2D 点云示例.

A more and robust way to find a "good" centerpoint might be to ignore the top and bottom 10% in each dimension and then calculate the average or median. As you can see you can define the centerpoint in different ways. Below I am showing you examples of 2 2D point clouds with these suggestions in mind.

深蓝色点是平均(平均)质心.中位数显示为绿色.中间显示为红色.在第二张图中,您将看到我之前所说的内容:绿点更接近"点云的最密集部分,而红点则离它更远,考虑到点云的最极端边界点云.

The dark blue dot is the average (mean) centroid. The median is shown in green. And the middle is shown in red. In the second image you will see exactly what I was talking about earlier: The green dot is "closer" to the densest part of the point cloud, while the red dot is further way from it, taking into account the most extreme boundaries of the point cloud.

这篇关于计算 3D(或 n-D)质心的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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