@Test public void testSurfacePointForSphere() { final Vector3d sphereVector = new Vector3d(spherePointSupplier.get()); sphereVector.mul(2.0); final Vector3dc surfacePoint = new Vector3d(sphereVector); final double distanceToSurfacePoint = distanceFromEllipsoidSurfaceOp .calculate(sphere, surfacePoint).get(); assertEquals("Distance to surface point failed", 0.0, distanceToSurfacePoint, 1.0e-12); }
@Override public DoubleType calculate(final Ellipsoid ellipsoid, final Vector3dc point) throws IllegalArgumentException { if (tolerance < 0.0) { throw new IllegalArgumentException("Tolerance cannot be negative"); } if (maxIterations < 1) { throw new IllegalArgumentException("Max iterations must be positive"); } final double a = ellipsoid.getA(); final double b = ellipsoid.getB(); final double c = ellipsoid.getC(); final Vector3dc pointInEllipsoidCoordinates = toEllipsoidCoordinates(point, ellipsoid); final double rootTerm = Math.sqrt(pointInEllipsoidCoordinates.x() * pointInEllipsoidCoordinates.x() / (a * a) + pointInEllipsoidCoordinates.y() * pointInEllipsoidCoordinates.y() / (b * b)); Vector2dc anglesK = new Vector2d(Math.atan2(a * pointInEllipsoidCoordinates.y(), b * pointInEllipsoidCoordinates.x()), Math .atan2(pointInEllipsoidCoordinates.z(), c * rootTerm)); Vector2d anglesKPlus1 = new Vector2d(0.0, 0.0); long iterations = 0; while (iterations < maxIterations) { anglesKPlus1 = new Vector2d(anglesK.x(), anglesK.y()); anglesKPlus1.add(inverseJacobian(anglesK, ellipsoid, pointInEllipsoidCoordinates)); if (getDifference(anglesK, anglesKPlus1) <= tolerance) { break; } anglesK = new Vector2d(anglesKPlus1.x, anglesKPlus1.y); iterations++; } final Vector3d closestPointOnEllipsoidSurface = getCartesianCoordinatesFromAngleParametrization(anglesKPlus1, ellipsoid); final Vector3d v = new Vector3d(closestPointOnEllipsoidSurface); v.negate(); v.add(pointInEllipsoidCoordinates); return new DoubleType(v.length()); }
DistanceFromEllipsoidSurfaceOp extends
	AbstractBinaryFunctionOp<Ellipsoid, Vector3dc, DoubleType> { @Override public DoubleType calculate(final Ellipsoid ellipsoid, final Vector3dc point) throws IllegalArgumentException { if (tolerance < 0.0) { throw new IllegalArgumentException("Tolerance cannot be negative"); } if (maxIterations < 1) { throw new IllegalArgumentException("Max iterations must be positive"); } final double a = ellipsoid.getA(); final double b = ellipsoid.getB(); final double c = ellipsoid.getC(); final Vector3dc pointInEllipsoidCoordinates = toEllipsoidCoordinates(point, ellipsoid); final double rootTerm = Math.sqrt(pointInEllipsoidCoordinates.x() * pointInEllipsoidCoordinates.x() / (a * a) + pointInEllipsoidCoordinates.y() * pointInEllipsoidCoordinates.y() / (b * b)); Vector2dc anglesK = new Vector2d(Math.atan2(a * pointInEllipsoidCoordinates.y(), b * pointInEllipsoidCoordinates.x()), Math .atan2(pointInEllipsoidCoordinates.z(), c * rootTerm)); Vector2d anglesKPlus1 = new Vector2d(0.0, 0.0); long iterations = 0; while (iterations < maxIterations) { anglesKPlus1 = new Vector2d(anglesK.x(), anglesK.y()); anglesKPlus1.add(inverseJacobian(anglesK, ellipsoid, pointInEllipsoidCoordinates)); if (getDifference(anglesK, anglesKPlus1) <= tolerance) { break; } anglesK = new Vector2d(anglesKPlus1.x, anglesKPlus1.y); iterations++; } final Vector3d closestPointOnEllipsoidSurface = getCartesianCoordinatesFromAngleParametrization(anglesKPlus1, ellipsoid); final Vector3d v = new Vector3d(closestPointOnEllipsoidSurface); v.negate(); v.add(pointInEllipsoidCoordinates); return new DoubleType(v.length()); } }
DistanceFromEllipsoidSurfaceOp extends
	AbstractBinaryFunctionOp<Ellipsoid, Vector3dc, DoubleType> { @Override public DoubleType calculate(final Ellipsoid ellipsoid, final Vector3dc point) throws IllegalArgumentException { if (tolerance < 0.0) { throw new IllegalArgumentException("Tolerance cannot be negative"); } if (maxIterations < 1) { throw new IllegalArgumentException("Max iterations must be positive"); } final double a = ellipsoid.getA(); final double b = ellipsoid.getB(); final double c = ellipsoid.getC(); final Vector3dc pointInEllipsoidCoordinates = toEllipsoidCoordinates(point, ellipsoid); final double rootTerm = Math.sqrt(pointInEllipsoidCoordinates.x() * pointInEllipsoidCoordinates.x() / (a * a) + pointInEllipsoidCoordinates.y() * pointInEllipsoidCoordinates.y() / (b * b)); Vector2dc anglesK = new Vector2d(Math.atan2(a * pointInEllipsoidCoordinates.y(), b * pointInEllipsoidCoordinates.x()), Math .atan2(pointInEllipsoidCoordinates.z(), c * rootTerm)); Vector2d anglesKPlus1 = new Vector2d(0.0, 0.0); long iterations = 0; while (iterations < maxIterations) { anglesKPlus1 = new Vector2d(anglesK.x(), anglesK.y()); anglesKPlus1.add(inverseJacobian(anglesK, ellipsoid, pointInEllipsoidCoordinates)); if (getDifference(anglesK, anglesKPlus1) <= tolerance) { break; } anglesK = new Vector2d(anglesKPlus1.x, anglesKPlus1.y); iterations++; } final Vector3d closestPointOnEllipsoidSurface = getCartesianCoordinatesFromAngleParametrization(anglesKPlus1, ellipsoid); final Vector3d v = new Vector3d(closestPointOnEllipsoidSurface); v.negate(); v.add(pointInEllipsoidCoordinates); return new DoubleType(v.length()); }  }
DistanceFromEllipsoidSurfaceOp extends
	AbstractBinaryFunctionOp<Ellipsoid, Vector3dc, DoubleType> { @Override public DoubleType calculate(final Ellipsoid ellipsoid, final Vector3dc point) throws IllegalArgumentException { if (tolerance < 0.0) { throw new IllegalArgumentException("Tolerance cannot be negative"); } if (maxIterations < 1) { throw new IllegalArgumentException("Max iterations must be positive"); } final double a = ellipsoid.getA(); final double b = ellipsoid.getB(); final double c = ellipsoid.getC(); final Vector3dc pointInEllipsoidCoordinates = toEllipsoidCoordinates(point, ellipsoid); final double rootTerm = Math.sqrt(pointInEllipsoidCoordinates.x() * pointInEllipsoidCoordinates.x() / (a * a) + pointInEllipsoidCoordinates.y() * pointInEllipsoidCoordinates.y() / (b * b)); Vector2dc anglesK = new Vector2d(Math.atan2(a * pointInEllipsoidCoordinates.y(), b * pointInEllipsoidCoordinates.x()), Math .atan2(pointInEllipsoidCoordinates.z(), c * rootTerm)); Vector2d anglesKPlus1 = new Vector2d(0.0, 0.0); long iterations = 0; while (iterations < maxIterations) { anglesKPlus1 = new Vector2d(anglesK.x(), anglesK.y()); anglesKPlus1.add(inverseJacobian(anglesK, ellipsoid, pointInEllipsoidCoordinates)); if (getDifference(anglesK, anglesKPlus1) <= tolerance) { break; } anglesK = new Vector2d(anglesKPlus1.x, anglesKPlus1.y); iterations++; } final Vector3d closestPointOnEllipsoidSurface = getCartesianCoordinatesFromAngleParametrization(anglesKPlus1, ellipsoid); final Vector3d v = new Vector3d(closestPointOnEllipsoidSurface); v.negate(); v.add(pointInEllipsoidCoordinates); return new DoubleType(v.length()); }  @Override DoubleType calculate(final Ellipsoid ellipsoid, final Vector3dc point); }
DistanceFromEllipsoidSurfaceOp extends
	AbstractBinaryFunctionOp<Ellipsoid, Vector3dc, DoubleType> { @Override public DoubleType calculate(final Ellipsoid ellipsoid, final Vector3dc point) throws IllegalArgumentException { if (tolerance < 0.0) { throw new IllegalArgumentException("Tolerance cannot be negative"); } if (maxIterations < 1) { throw new IllegalArgumentException("Max iterations must be positive"); } final double a = ellipsoid.getA(); final double b = ellipsoid.getB(); final double c = ellipsoid.getC(); final Vector3dc pointInEllipsoidCoordinates = toEllipsoidCoordinates(point, ellipsoid); final double rootTerm = Math.sqrt(pointInEllipsoidCoordinates.x() * pointInEllipsoidCoordinates.x() / (a * a) + pointInEllipsoidCoordinates.y() * pointInEllipsoidCoordinates.y() / (b * b)); Vector2dc anglesK = new Vector2d(Math.atan2(a * pointInEllipsoidCoordinates.y(), b * pointInEllipsoidCoordinates.x()), Math .atan2(pointInEllipsoidCoordinates.z(), c * rootTerm)); Vector2d anglesKPlus1 = new Vector2d(0.0, 0.0); long iterations = 0; while (iterations < maxIterations) { anglesKPlus1 = new Vector2d(anglesK.x(), anglesK.y()); anglesKPlus1.add(inverseJacobian(anglesK, ellipsoid, pointInEllipsoidCoordinates)); if (getDifference(anglesK, anglesKPlus1) <= tolerance) { break; } anglesK = new Vector2d(anglesKPlus1.x, anglesKPlus1.y); iterations++; } final Vector3d closestPointOnEllipsoidSurface = getCartesianCoordinatesFromAngleParametrization(anglesKPlus1, ellipsoid); final Vector3d v = new Vector3d(closestPointOnEllipsoidSurface); v.negate(); v.add(pointInEllipsoidCoordinates); return new DoubleType(v.length()); }  @Override DoubleType calculate(final Ellipsoid ellipsoid, final Vector3dc point);  }