/** * Creates an AffineMatrix representing a rotation about the origin by some angle around the given * axis. * * @param theta double * @param axis double[] * @return AffineMatrix */ public static Affine3DMatrix Rotation(double theta, double[] axis) { Affine3DMatrix at = new Affine3DMatrix(null); double[][] atMatrix = at.matrix; double norm = Math.sqrt(axis[0] * axis[0] + axis[1] * axis[1] + axis[2] * axis[2]); double x = axis[0] / norm, y = axis[1] / norm, z = axis[2] / norm; double c = Math.cos(theta), s = Math.sin(theta); double t = 1 - c; // matrix elements not listed are zero atMatrix[0][0] = t * x * x + c; atMatrix[0][1] = t * x * y - s * z; atMatrix[0][2] = t * x * y + s * y; atMatrix[1][0] = t * x * y + s * z; atMatrix[1][1] = t * y * y + c; atMatrix[1][2] = t * y * z - s * x; atMatrix[2][0] = t * x * z - s * y; atMatrix[2][1] = t * y * z + s * x; atMatrix[2][2] = t * z * z + c; atMatrix[3][3] = 1; return at; }