DistanceFromEllipsoidSurfaceOp extends
	AbstractBinaryFunctionOp<Ellipsoid, Vector3dc, DoubleType> { static Vector3dc toEllipsoidCoordinates(final Vector3dc point, final Ellipsoid ellipsoid) { final Vector3d translated = new Vector3d(ellipsoid.getCentroid()); translated.mul(-1.0); translated.add(point); final Matrix4dc orientation = ellipsoid.getOrientation(); final double x = orientation.m00() * translated.x + orientation.m10() * translated.y + orientation.m20() * translated.z; final double y = orientation.m01() * translated.x + orientation.m11() * translated.y + orientation.m21() * translated.z; final double z = orientation.m02() * translated.x + orientation.m12() * translated.y + orientation.m22() * translated.z; return new Vector3d(x, y, z); }  @Override DoubleType calculate(final Ellipsoid ellipsoid, final Vector3dc point);  }
@Test public void testRotationTransformation() { final Ellipsoid ellipsoid = new Ellipsoid(1.0, 2.0, 3.0); ellipsoid.setOrientation(new Matrix3d(0, 0, 1, 0, -1, 0, 1, 0, 0)); final Vector3dc point = new Vector3d(0, 0, 8); final Vector3dc rotated = DistanceFromEllipsoidSurfaceOp .toEllipsoidCoordinates(point, ellipsoid); assertEquals(8.0, rotated.x(), 1.0e-12); assertEquals(0.0, rotated.y(), 1.0e-12); assertEquals(0.0, rotated.z(), 1.0e-12); }
@Test public void testTranslationTransformation() { final Ellipsoid ellipsoid = new Ellipsoid(2.0, 2.0, 2.0); ellipsoid.setCentroid(new Vector3d(5, 7, 8)); final Vector3dc point = new Vector3d(5, 7, 9); final Vector3dc translated = DistanceFromEllipsoidSurfaceOp .toEllipsoidCoordinates(point, ellipsoid); assertEquals(0.0, translated.x(), 1.0e-12); assertEquals(0.0, translated.y(), 1.0e-12); assertEquals(1.0, translated.z(), 1.0e-12); }