Ellipsoid { public List<Vector3d> samplePoints(final long n) throws RuntimeException { if (!samplingInitialized()) { throw new RuntimeException("Sampling has not been initialized"); } final List<Vector3d> points = isotropicSampling.calculate(new double[] { a, b, c }, n); points.forEach(this::mapToOrientation); points.forEach(p -> p.add(centroid)); return points; } Ellipsoid(final double a, final double b, final double c);  Ellipsoid(final Vector3dc u, final Vector3dc v, final Vector3dc w); double getA(); void setA(final double a); double getB(); void setB(final double b); double getC(); void setC(final double c); Vector3d getCentroid(); void setCentroid(final Vector3dc centroid); Matrix4d getOrientation(); void setOrientation(final Matrix3dc semiAxes); List<Vector3d> getSemiAxes(); double getVolume(); @SuppressWarnings("unchecked") void initSampling(final OpEnvironment ops); List<Vector3d> samplePoints(final long n); void setSemiAxes(final Vector3dc u, final Vector3dc v,
		final Vector3dc w);  }
@Test public void testSamplePoints() { final double a = 2.0; final double b = 3.0; final double c = 4.0; final Ellipsoid ellipsoid = new Ellipsoid(a, b, c); final Vector3dc centroid = new Vector3d(4, 5, 6); ellipsoid.setCentroid(centroid); final double sinAlpha = Math.sin(Math.PI / 4.0); final double cosAlpha = Math.cos(Math.PI / 4.0); final Matrix3dc orientation = new Matrix3d( cosAlpha, -sinAlpha, 0, sinAlpha, cosAlpha, 0, 0, 0, 1 ); final AxisAngle4d invRotation = new AxisAngle4d(); invRotation.set(orientation); invRotation.angle = -invRotation.angle; final Quaterniondc q = new Quaterniond(new AxisAngle4d(invRotation.angle, invRotation.x, invRotation.y, invRotation.z)); final BinaryHybridCFI1<Vector3d, Quaterniondc, Vector3d> inverseRotation = Hybrids.binaryCFI1(IMAGE_J.op(), Rotate3d.class, Vector3d.class, new Vector3d(), q); ellipsoid.setOrientation(orientation); final long n = 10; final Function<Vector3d, Double> ellipsoidEq = (Vector3d p) -> { final BiFunction<Double, Double, Double> term = (x, r) -> (x * x) / (r * r); return term.apply(p.x, a) + term.apply(p.y, b) + term.apply(p.z, c); }; ellipsoid.initSampling(IMAGE_J.op()); final List<Vector3d> points = ellipsoid.samplePoints(n); assertNotNull(points); assertEquals(n, points.size()); points.forEach(p -> p.sub(centroid)); points.forEach(inverseRotation::mutate); points.forEach(p -> assertEquals( "Point doesn't solve the ellipsoid equation", 1.0, ellipsoidEq.apply(p), 1e-5)); }
@Test(expected = RuntimeException.class) public void testSamplePointsThrowsRuntimeExceptionIfNotInitialized() { final Ellipsoid ellipsoid = new Ellipsoid(1, 2, 3); ellipsoid.samplePoints(10); }