/** * Convert a four-d matrix to a double array. Row-packed. * @param transformationMatrix the input matrix4d object * @return the double array (16 long). */ public static double[] convertToDoubleArray(Matrix4d transformationMatrix) { // Initialise the output array double[] outArray = new double[16]; // Iterate over the matrix for(int i=0; i<4; i++){ for(int j=0; j<4; j++){ // Now set this element outArray[i*4+j] = transformationMatrix.getElement(i,j); } } return outArray; }
public static void assertMatrix4dEquals(String message, Matrix4d expected, Matrix4d actual, double delta) { int size = 4; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { assertEquals(message, actual.getElement(i, j), expected.getElement(i, j), delta); } } }
@Override public ResultSample doInverse3Test(final int count, final int maxCount, final long timeOutMS) { final Matrix4d mat = vecMatrixRandom(); final Matrix3d m1 = new Matrix3d( // mat.getElement(0, 0), mat.getElement(0, 1), mat.getElement(0, 2), // mat.getElement(1, 0), mat.getElement(1, 1), mat.getElement(1, 2), // mat.getElement(2, 0), mat.getElement(2, 1), mat.getElement(2, 2)); mat.setIdentity(); final long start = System.currentTimeMillis(); int loopCount = 0; while (System.currentTimeMillis() - start < timeOutMS && loopCount != maxCount) { ++loopCount; for (int i = 0; i < count; ++i) { m1.invert(); } } mat.set(m1); return populateResult(System.currentTimeMillis() - start, loopCount, toArray(mat)); }
A[i][j] = input.getElement(i, j);
origString +" + (%9.6f)*Z"+ origString +" + (%12.6f)", btransforms.get(str).getElement(0,0), btransforms.get(str).getElement(0,1), btransforms.get(str).getElement(0,2), btransforms.get(str).getElement(0,3))); txt.append( "\n"); txt.append(String.format(" Y"+(str+1)+" = (%9.6f)*X"+ origString +" + (%9.6f)*Z"+ origString +" + (%12.6f)", btransforms.get(str).getElement(1,0), btransforms.get(str).getElement(1,1), btransforms.get(str).getElement(1,2), btransforms.get(str).getElement(1,3))); txt.append( "\n"); txt.append(String.format(" Z"+(str+1)+" = (%9.6f)*X"+ origString +" + (%9.6f)*Z"+ origString +" + (%12.6f)", btransforms.get(str).getElement(2,0), btransforms.get(str).getElement(2,1), btransforms.get(str).getElement(2,2), btransforms.get(str).getElement(2,3))); txt.append("\n\n");
/** * Convert a transformation matrix into a JAMA rotation matrix. Because the * JAMA matrix is a pre-multiplication matrix and the Vecmath matrix is a * post-multiplication one, the rotation matrix is transposed to ensure that * the transformation they produce is the same. * * @param transform * Matrix4d with transposed rotation matrix * @return rotation matrix as JAMA object */ public static Matrix getRotationJAMA(Matrix4d transform) { Matrix rot = new Matrix(3, 3); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { rot.set(j, i, transform.getElement(i, j)); // transposed } } return rot; }
/** * @return true if this transformation holds an identity matrix (e.g. doesn't transform at all). */ @Override public boolean isIdentity() { if ( numRow != numCol ) { return false; } for ( int row = 0; row < numRow; row++ ) { for ( int col = 0; col < numCol; col++ ) { double value = ( matrix3D != null ) ? matrix3D.getElement( row, col ) : ( ( matrix4D != null ) ? matrix4D.getElement( row, col ) : matrix.getElement( row, col ) ); if ( Math.abs( value - ( col == row ? 1 : 0 ) ) > EPS11 ) { return false; } } } return true; }
coef = matTransform.getElement(i, 0); coef = matTransform.getElement(i, 1); coef = matTransform.getElement(i, 2); coef = matTransform.getElement(i, 3);
public synchronized static void printXMLmatrix4d(PrettyXMLWriter xml, Matrix4d transform) throws IOException { if (transform == null) return; xml.openTag("Matrix4d"); for (int x=0;x<4;x++){ for (int y=0;y<4;y++){ String key = "mat"+(x+1)+(y+1); String value = transform.getElement(x,y)+""; xml.attribute(key,value); } } xml.closeTag("Matrix4d"); }
for (int i=0;i<3;i++) { for (int j=0;j<3;j++) { if (!deltaComp(mtranspose.getElement(i, j),scaleMatrix.getElement(i, j))) { if (!deltaComp(scaleMatrix.getElement(i, 3),0)) { return false;
public void toXML(PrettyXMLWriter xml) throws IOException{ xml.openTag("transformation"); xml.attribute("index",id); xml.openTag("matrix"); for ( int i = 0 ; i<3 ; i++){ for ( int j = 0 ; j<3 ;j++){ xml.attribute("m" + (i+1) + (j+1), String.format("%.8f",transformation.getElement(i,j))); } } xml.closeTag("matrix"); xml.openTag("shift"); for ( int i = 0 ; i<3 ; i++) { xml.attribute("v"+(i+1),String.format("%.8f", transformation.getElement(i,3))); } xml.closeTag("shift"); xml.closeTag("transformation"); }
/** * recupere la matrice transformation de l'objet. */ public double[][] getMatrice() { final Matrix4d m = new Matrix4d(); final Transform3D t = new Transform3D(); tg_.getTransform(t); t.get(m); final double[][] d = new double[4][4]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { d[i][j] = m.getElement(j, i); } } return d; }