import javax.vecmath.Matrix4d;
import javax.vecmath.Matrix3d;

public class MatrixTest
{
    public static void main(String args[])
    {
	Matrix4d m4 = 
	    new Matrix4d( 0.996823,  0.036243, 0.070927, -0.245034,
			 -0.036412,  0.997481, 0.001096,  0.034035,
			-0.070840, -0.003675, 0.999336,  0.036529,
			 0.0,       0.0,      0.0,       1.0);
	Matrix3d m3 = new Matrix3d();

	m4.get(m3);

	System.err.println("4x4: \n" + m4);
	System.err.println("\n3x3: \n" + m3);

	for (int row = 0; row < 3; row++) {
	    double t = 0.0;
	    for (int col = 0; col < 3; col++) {
		t += Math.pow(m4.getElement(row, col), 2.0);
	    }
	    System.out.println("row " + row + ": " + Math.sqrt(t));
	    for (int col = 0; col < 3; col++) {
		m4.setElement(row, col, m4.getElement(row, col) / t);
	    }
	    
	}

	m4.get(m3);

	System.err.println("\n4x4: \n" + m4);
	System.err.println("\n3x3: \n" + m3);

	for (int row = 0; row < 3; row++) {
	    double t = 0.0;
	    for (int col = 0; col < 3; col++) {
		t += Math.pow(m4.getElement(row, col), 2.0);
	    }
	    System.out.println("row " + row + ": " + Math.sqrt(t));
	    for (int col = 0; col < 3; col++) {
		m4.setElement(row, col, m4.getElement(row, col) / t);
	    }
	    
	}

	for (int row = 0; row < 3; row++) {
	    double t = 0.0;
	    for (int col = 0; col < 3; col++) {
		t += Math.pow(m4.getElement(row, col), 2.0);
	    }
	    System.out.println("row " + row + ": " + Math.sqrt(t));
	}

    }
}
