在 Java 中将 3D 线拟合到 3D 点数据?

发布于 2024-08-23 15:19:39 字数 132 浏览 4 评论 0原文

我花了相当多的时间试图寻找一种简单的方法来做到这一点 - 理想情况下,某个地方存在一个神奇的库,它可以获取我的一组 3D 数据点,并使用正交函数在最佳拟合线上返回 2 个点回归或最小二乘法,还返回拟合线的误差。这样的事情存在吗?如果存在的话,在哪里?

I've spent a decent amount of time trying to hunt down a simple way of doing this - ideally, a magical library exists out there somewhere that will take my set of 3D data points and return 2 points on the best fit line using either orthogonal regression or least squares and also return the error of the fitted line. Does such a thing exist, and if so, where?

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

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

发布评论

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

评论(1

甜味超标? 2024-08-30 15:19:39

这很容易做到,但要自己编写,您将需要特征值求解器或奇异值分解。创建 (x-xbar, y-ybar, z-zbar) 数据的 nx3 矩阵 A 作为列。保存这些列意味着稍后,我将其称为 V0 = [xbar,ybar,zbar]。

现在,计算 A'*A 的特征值和特征向量,即由 A 转置乘以 A 形成的 3x3 矩阵。

如果该数据位于 R^3 中的一条线上,则其中一个特征值将明显大于另一个两个特征值。如果事实并非如此,则正交回归线将无法得到很好的估计。

取与 A'*A 的最大特征值相关的特征向量。然后,如果 V 是相应的特征向量,则正交回归线定义为

V(t) = V0 + t*V

该线上的任何点都可以由参数 t 的某个值给出。

或者,计算 A 的奇异值分解,并取与 A 的最大奇异值相对应的右奇异向量。

在任何一种情况下,如果您希望计算数据点的误差,这将被简单地定义为正交到相关线的距离。

This is easy enough to do, but to write it yourself you will need an eigenvalue solver or a singular value decomposition. Create the nx3 matrix A, of your (x-xbar, y-ybar, z-zbar) data as columns. Save those column means for later, I'll call it V0 = [xbar,ybar,zbar].

Now, compute the eigenvalues and eigenvectors of A'*A, i.e., the 3x3 matrix formed from A transpose multiplied by A.

If this data lies on a line in R^3, then one of those eigenvalues will be significantly larger than the other two eigenvalues. If this is not true, then the orthogonal regression line will not be well estimated.

Take the eigenvector that is associated with the largest eigenvalue of A'*A. Then if V is the corresponding eigenvector, the orthogonal regression line is defined as

V(t) = V0 + t*V

Any point on that line can be given by some value of the parameter t.

Alternatively, compute the singular value decomposition of A, and take the right singular vector which corresponds to the largest singular value of A.

In either event, if you wish to compute the errors for the data points, this would be defined as simply the orthogonal distance to the line in question.

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