/** * Converts this quaternion to a rotation matrix and then extracts rotation axes. * * @param axes * the array of vectors to be filled. * @throws ArrayIndexOutOfBoundsException * if the given axes array is smaller than 3 elements. * @return the axes */ @Override public Vector3[] toAxes(final Vector3[] axes) { final Matrix3 tempMat = toRotationMatrix(Matrix3.fetchTempInstance()); axes[2] = tempMat.getColumn(2, axes[2]); axes[1] = tempMat.getColumn(1, axes[1]); axes[0] = tempMat.getColumn(0, axes[0]); Matrix3.releaseTempInstance(tempMat); return axes; }
/** * Converts this quaternion to a rotation matrix and then extracts rotation axes. * * @param axes * the array of vectors to be filled. * @throws ArrayIndexOutOfBoundsException * if the given axes array is smaller than 3 elements. * @return the axes */ @Override public Vector3[] toAxes(final Vector3[] axes) { final Matrix3 tempMat = toRotationMatrix(Matrix3.fetchTempInstance()); axes[2] = tempMat.getColumn(2, axes[2]); axes[1] = tempMat.getColumn(1, axes[1]); axes[0] = tempMat.getColumn(0, axes[0]); Matrix3.releaseTempInstance(tempMat); return axes; }
@Test public void testAxes() { final Matrix3 rot = new Matrix3().applyRotationX(MathUtils.QUARTER_PI).applyRotationY(MathUtils.HALF_PI); final Quaternion quat1 = new Quaternion().fromAxes(rot.getColumn(0, null), rot.getColumn(1, null), rot.getColumn(2, null)); final Quaternion quat2 = new Quaternion().fromRotationMatrix(rot); assertEquals(quat2, quat1); final Vector3[] axes = quat1.toAxes(new Vector3[3]); quat1.fromAxes(axes[0], axes[1], axes[2]); assertEquals(quat2, quat1); }
mat3A.setColumn(1, new Vector3(1, 4, 7)); mat3A.setColumn(2, new Vector3(2, 5, 8)); assertEquals(new Vector3(0, 3, 6), mat3A.getColumn(0, new Vector3())); assertEquals(new Vector3(1, 4, 7), mat3A.getColumn(1, null)); assertEquals(new Vector3(2, 5, 8), mat3A.getColumn(2, null)); try { mat3A.getColumn(-1, null); fail("getColumn(-1, null) should have thrown IllegalArgumentException."); } catch (final IllegalArgumentException e) { mat3A.getColumn(3, null); fail("getColumn(3, null) should have thrown IllegalArgumentException."); } catch (final IllegalArgumentException e) {