Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何计算估计的x';y';z';使用包含物理坐标系的标称和测量数据点的输入阵列?_Java_Numpy_Linear Algebra_Apache Commons Math_Ejml - Fatal编程技术网

Java 如何计算估计的x';y';z';使用包含物理坐标系的标称和测量数据点的输入阵列?

Java 如何计算估计的x';y';z';使用包含物理坐标系的标称和测量数据点的输入阵列?,java,numpy,linear-algebra,apache-commons-math,ejml,Java,Numpy,Linear Algebra,Apache Commons Math,Ejml,我的要求是在Java中提供一个函数,该函数使用线性代数在三维坐标系中查找“校准”的xyz位置。下面是我试图实现的接口。如果需要,可以更改参数以适合特定的库 /** * Given a nominal target xyz point within a three dimensional robotic coordinate system, calculate the theoretical x'y'z' * transformation using input arrays that rep

我的要求是在Java中提供一个函数,该函数使用线性代数在三维坐标系中查找“校准”的xyz位置。下面是我试图实现的接口。如果需要,可以更改参数以适合特定的库

/**
 * Given a nominal target xyz point within a three dimensional robotic coordinate system, calculate the theoretical x'y'z'
 * transformation using input arrays that represent the nominal coordinates and actual measured coordinates corresponding to
 * each nominal point.
 *
 * @param nominalPoints - a sampling of nominal values (per engineering specs) for a 3-axis robotic system
 *    e.g.     double[][] nominalPoints = new double[][]{
 *                 new double[]{30.0d, 68.0d, 1.0d},
 *                 new double[]{50.0d, 6.0d, 1.0d},
 *                 new double[]{110.d, 20.0d, 1.0d},
 *                 new double[]{35.0d, 15.0d, 1.0d},
 *                 new double[]{45.0d, 97.0d, 1.0d}
 *              };
 * @param actualPoints - actual/measured values corresponding to the nominal data points.  These points represent the
 *                     variance from nominal due to manufacturing tolerances.
 *    e.g     double[][] measuredPoints = new double[][]{
 *                 new double[]{30.5d, 68.1d, 1.01d},
 *                 new double[]{50.4d, 6.2d, 1.02d},
 *                 new double[]{110.3d, 20.3d, 1.03d},
 *                 new double[]{35.2d, 15.4d, 1.04d},
 *                 new double[]{45.1d, 97.5d, 1.05d}
 *             };
 * @param targetPoint - an x/y/z point in system to transform into an estimated value based on a least-squared evaluation of the
 *                    nominal and actual arrays
 *
 *     e.g.    float[] targetPoint = new float[]{75.21f, 17.56f, 2.765f};
 *
 * @return
 */
public float[] getCalibratedPoint(float[][] nominalPoints, float[][] actualPoints, float[] targetPoint);
下面的代码是一个解决方案,我被告知它可以在Python中使用numpy,但我对线性代数一窍不通,很难在Java中找到实现。具体地说,我还没有找到一个与np.hstack(..)、np.ones(..)等价的函数,以及一个接受两个数组参数的最小二乘函数,如np.linalg.lstsq(..)。到目前为止,我已经研究了apachecommons和EJML

import numpy as np

# These are the points in the Tray Coordinate System.
primary = np.array([[40., 1160., 0.],
                    [40., 40., 0.],
                    [260., 40., 0.],
                    [260., 1160., 0.]])

# These are points in the Stage Coordinate System.
secondary = np.array([[610., 560., 0.],
                      [610., -560., 0.],
                      [390., -560., 0.],
                      [390., 560., 0.]])

# Pad the data with ones, so that our transformation can do translations too
def pad(x): return np.hstack([x, np.ones((x.shape[0], 1))])
def unpad(x): return x[:, :-1]

# This is the transform function. Pass Tray Coordinates to this.
def transform(x): return unpad(np.dot(pad(x), A))

X = pad(primary)
Y = pad(secondary)

# Solve the least squares problem X * A = Y
# to find our transformation matrix A
A, res, rank, s = np.linalg.lstsq(X, Y, rcond=None)  # This is where the important work is done.

# Transforming a single point.
print('Transforming point (1, 2, 3) ...')
print(transform(np.array([[1, 2, 3]])))

呃,这段Java代码使用数组数组来表示矩阵(保证了糟糕的性能,因为不同的行将位于堆中的随机位置)。尽管如此,(1)用Java编写
pad
函数(使用hstack和ones)非常简单:在输入的每行末尾添加1。和(2)有什么问题吗?Python中的数组
X
是方形的,因此您可以使用
LUDecomposition
,就像这里的示例一样,然后使用
solver.solve(Y)
。如果有任何问题,请尝试此更新。作为后续,我无法找到与上述python代码输出匹配的基于Java的解决方案。LUDecomposition和Solver的结果与np.linalg.lstsq的结果不同。最后,我使用jep从java服务内部执行python代码。它工作得很好,但我仍然对纯java解决方案感兴趣。发布java和您从Python获得的预期输出,我们可以尝试解决它。呃,这个java代码使用数组来表示矩阵(保证了糟糕的性能,因为不同的行将位于堆中的随机位置)。尽管如此,(1)用Java编写
pad
函数(使用hstack和ones)非常简单:在输入的每行末尾添加1。和(2)有什么问题吗?Python中的数组
X
是方形的,因此您可以使用
LUDecomposition
,就像这里的示例一样,然后使用
solver.solve(Y)
。如果有任何问题,请尝试此更新。作为后续,我无法找到与上述python代码输出匹配的基于Java的解决方案。LUDecomposition和Solver的结果与np.linalg.lstsq的结果不同。最后,我使用jep从java服务内部执行python代码。它工作得很好,但我仍然对纯java解决方案感兴趣。发布java和您从Python获得的预期输出,我们可以尝试解决它。