将 3D 线拟合到 Java 中的 3D 点数据? [英] Fit a 3D line to 3D point data in Java?

查看:27
本文介绍了将 3D 线拟合到 Java 中的 3D 点数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了很多时间试图寻找一种简单的方法来做到这一点 - 理想情况下,有一个神奇的库存在于某处,可以获取我的一组 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?

推荐答案

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

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].

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

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

如果此数据位于 R^3 中的一条线上,那么这些特征值之一将明显大于其他两个特征值.如果这不是真的,那么就不能很好地估计正交回归线.

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.

取与 A'*A 的最大特征值相关联的特征向量.那么如果V是对应的特征向量,则正交回归线定义为

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

V(t) = V0 + t*V

这条线上的任何点都可以由参数 t 的某个值给出.

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

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

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.

这篇关于将 3D 线拟合到 Java 中的 3D 点数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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