public static double[][] rotateAroundForeignAxes(double[][] matrix,
			double xangle, double yangle, double zangle, double[][] foreign) {

		double[][] rotation = getRotationFromTransform(foreign);

		double[][] rotated = matrix;
		boolean copy = true;

		if (xangle != 0d) {

			rotated = rotateAroundArbitraryAxis(rotated, xangle, rotation[0]);
			copy = false;

		}

		if (yangle != 0d) {

			rotated = rotateAroundArbitraryAxis(rotated, yangle, rotation[1]);
			copy = false;

		}

		if (zangle != 0d) {

			rotated = rotateAroundArbitraryAxis(rotated, zangle, rotation[2]);
			copy = false;

		}

		if (copy) {

			// copy the specified matrix because the caller may otherwise
			// inadvertently modify the specified matrix were it returned by
			// default
			rotated = copyMatrix(rotated);

		}

		return rotated;

	}