use of org.apache.commons.math3.linear.RealVector in project imagingbook-common by imagingbook.
the class ProcrustesFit method makeDataMatrix.
private RealMatrix makeDataMatrix(List<double[]> X) {
final int m = X.size();
final int n = X.get(0).length;
RealMatrix M = MatrixUtils.createRealMatrix(n, m);
int i = 0;
for (double[] x : X) {
RealVector xi = MatrixUtils.createRealVector(x);
M.setColumnVector(i, xi);
i++;
}
return M;
}
use of org.apache.commons.math3.linear.RealVector in project FSensor by KalebKE.
the class CalibrationUtil method calibrate.
/**
* Compensate for hard and soft iron distortions (magnetic) or sensor skew and offsets (acceleration) depending on the sensor type.
*
* @param vector the vector to be compensated.
* @param calibration the calibration to be applied
* @return the compensated vector
*/
public static float[] calibrate(float[] vector, Calibration calibration) {
RealVector point = new ArrayRealVector(3);
point.setEntry(0, vector[0]);
point.setEntry(1, vector[1]);
point.setEntry(2, vector[2]);
point = calibration.scalar.operate((point.subtract(calibration.offset)));
vector[0] = (float) point.getEntry(0);
vector[1] = (float) point.getEntry(1);
vector[2] = (float) point.getEntry(2);
return vector;
}
use of org.apache.commons.math3.linear.RealVector in project FSensor by KalebKE.
the class FitPoints method formAlgebraicMatrix.
/**
* Create a matrix in the algebraic form of the polynomial Ax^2 + By^2 +
* Cz^2 + 2Dxy + 2Exz + 2Fyz + 2Gx + 2Hy + 2Iz = 1.
*
* @param v the vector polynomial.
* @return the matrix of the algebraic form of the polynomial.
*/
private RealMatrix formAlgebraicMatrix(RealVector v) {
// a =
// [ Ax^2 2Dxy 2Exz 2Gx ]
// [ 2Dxy By^2 2Fyz 2Hy ]
// [ 2Exz 2Fyz Cz^2 2Iz ]
// [ 2Gx 2Hy 2Iz -1 ] ]
RealMatrix a = new Array2DRowRealMatrix(4, 4);
a.setEntry(0, 0, v.getEntry(0));
a.setEntry(0, 1, v.getEntry(3));
a.setEntry(0, 2, v.getEntry(4));
a.setEntry(0, 3, v.getEntry(6));
a.setEntry(1, 0, v.getEntry(3));
a.setEntry(1, 1, v.getEntry(1));
a.setEntry(1, 2, v.getEntry(5));
a.setEntry(1, 3, v.getEntry(7));
a.setEntry(2, 0, v.getEntry(4));
a.setEntry(2, 1, v.getEntry(5));
a.setEntry(2, 2, v.getEntry(2));
a.setEntry(2, 3, v.getEntry(8));
a.setEntry(3, 0, v.getEntry(6));
a.setEntry(3, 1, v.getEntry(7));
a.setEntry(3, 2, v.getEntry(8));
a.setEntry(3, 3, -1);
return a;
}
use of org.apache.commons.math3.linear.RealVector in project FSensor by KalebKE.
the class FitPoints method generateRIV.
/**
* Generates a vector from the identity matrix of r.
*
* @param subr centered algebraic form of the ellipsoid
*/
private RealVector generateRIV(RealMatrix subr) {
riv = new ArrayRealVector(3);
riv.setEntry(0, Math.abs(subr.getEntry(0, 0)));
riv.setEntry(1, Math.abs(subr.getEntry(1, 1)));
riv.setEntry(2, Math.abs(subr.getEntry(2, 2)));
return riv;
}
use of org.apache.commons.math3.linear.RealVector in project FSensor by KalebKE.
the class FitPoints method findCenter.
/**
* Find the offset of the ellipsoid.
*
* @param a the algebraic from of the polynomial.
* @return a vector containing the offset of the ellipsoid.
*/
private RealVector findCenter(RealMatrix a) {
RealMatrix subA = a.getSubMatrix(0, 2, 0, 2);
for (int q = 0; q < subA.getRowDimension(); q++) {
for (int s = 0; s < subA.getColumnDimension(); s++) {
subA.multiplyEntry(q, s, -1.0);
}
}
RealVector subV = a.getRowVector(3).getSubVector(0, 3);
// inv (dtd)
DecompositionSolver solver = new SingularValueDecomposition(subA).getSolver();
RealMatrix subAi = solver.getInverse();
return subAi.operate(subV);
}
Aggregations