Java Code Examples for javax.vecmath.Matrix4d#getElement()

The following examples show how to use javax.vecmath.Matrix4d#getElement() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultipleAlignmentXMLConverter.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
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");
}
 
Example 2
Source File: MmtfUtils.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: BasePairParameters.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * This method calculates pairing and step parameters from 4x4 transformation matrices (used internally)
 * that comes out as a Matrix4d.
 * @param input the 4x4 matrix representing the transformation from strand II -> strand I or pair i to pair i+1
 * @return Six parameters as double[6]
 */
public static double[] calculateTp(Matrix4d input) {

	double[][] A = new double[4][4];
	for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) {
		A[i][j] = input.getElement(i, j);
	}
	double[] M = new double[6];

	double cosgamma, gamma, phi, omega, sgcp, omega2_minus_phi,
			sm, cm, sp, cp, sg, cg;

	cosgamma = A[2][2];
	if (cosgamma > 1.0) cosgamma = 1.0;
	else if (cosgamma < -1.0) cosgamma = -1.0;

	gamma = acos(cosgamma);

	sgcp = A[1][1]*A[0][2]-A[0][1]*A[1][2];

	if (gamma == 0.0) omega = -atan2(A[0][1],A[1][1]);
	else omega = atan2(A[2][1]*A[0][2]+sgcp*A[1][2],sgcp*A[0][2]-A[2][1]*A[1][2]);

	omega2_minus_phi = atan2(A[1][2],A[0][2]);

	phi = omega/2.0 - omega2_minus_phi;

	M[0] = gamma*sin(phi)*180.0/PI;
	M[1] = gamma*cos(phi)*180.0/PI;
	M[2] = omega*180.0/PI;

	sm = sin(omega/2.0-phi);
	cm = cos(omega/2.0-phi);
	sp = sin(phi);
	cp = cos(phi);
	sg = sin(gamma/2.0);
	cg = cos(gamma/2.0);

	M[3] = (cm*cg*cp-sm*sp)*A[0][3]+(sm*cg*cp+cm*sp)*A[1][3]-sg*cp*A[2][3];
	M[4] = (-cm*cg*sp-sm*cp)*A[0][3]+(-sm*cg*sp+cm*cp)*A[1][3]+sg*sp*A[2][3];
	M[5] = (cm*sg)*A[0][3]+(sm*sg)*A[1][3]+cg*A[2][3];

	return M;

}