@Test public void testUnitSphere() { final Matrix4d expectedOrientation = new Matrix4d().identity(); final Optional<Ellipsoid> result = quadricToEllipsoid.calculate( UNIT_SPHERE); assertTrue(result.isPresent()); final Ellipsoid unitSphere = result.get(); assertEquals(1.0, unitSphere.getA(), 1e-12); assertEquals(1.0, unitSphere.getB(), 1e-12); assertEquals(1.0, unitSphere.getC(), 1e-12); final Vector3d c = unitSphere.getCentroid(); assertTrue(epsilonEquals(new Vector3d(0, 0, 0), new Vector3d(c.x, c.y, c.z), 1e-12)); epsilonEquals(expectedOrientation, unitSphere.getOrientation(), 1e-12); }
@Override public Optional<Ellipsoid> calculate(final Matrix4dc quadricSolution) { final Vector3dc center = findCenter(quadricSolution); final Matrix4dc translated = translateToCenter(quadricSolution, center); final EigenDecomposition decomposition = solveEigenDecomposition( translated); final boolean invalidEv = Arrays.stream(decomposition.getRealEigenvalues()) .anyMatch(e -> e <= 0.0); if (invalidEv) { return Optional.empty(); } final double[] radii = Arrays.stream(decomposition.getRealEigenvalues()) .map(ev -> Math.sqrt(1.0 / ev)).toArray(); final Ellipsoid ellipsoid = new Ellipsoid(radii[0], radii[1], radii[2]); ellipsoid.setCentroid(center); final Matrix3dc orientation = toOrientationMatrix(decomposition); ellipsoid.setOrientation(orientation); return Optional.of(ellipsoid); }
QuadricToEllipsoid extends
	AbstractUnaryFunctionOp<Matrix4dc, Optional<Ellipsoid>> { @Override public Optional<Ellipsoid> calculate(final Matrix4dc quadricSolution) { final Vector3dc center = findCenter(quadricSolution); final Matrix4dc translated = translateToCenter(quadricSolution, center); final EigenDecomposition decomposition = solveEigenDecomposition( translated); final boolean invalidEv = Arrays.stream(decomposition.getRealEigenvalues()) .anyMatch(e -> e <= 0.0); if (invalidEv) { return Optional.empty(); } final double[] radii = Arrays.stream(decomposition.getRealEigenvalues()) .map(ev -> Math.sqrt(1.0 / ev)).toArray(); final Ellipsoid ellipsoid = new Ellipsoid(radii[0], radii[1], radii[2]); ellipsoid.setCentroid(center); final Matrix3dc orientation = toOrientationMatrix(decomposition); ellipsoid.setOrientation(orientation); return Optional.of(ellipsoid); } }
QuadricToEllipsoid extends
	AbstractUnaryFunctionOp<Matrix4dc, Optional<Ellipsoid>> { @Override public Optional<Ellipsoid> calculate(final Matrix4dc quadricSolution) { final Vector3dc center = findCenter(quadricSolution); final Matrix4dc translated = translateToCenter(quadricSolution, center); final EigenDecomposition decomposition = solveEigenDecomposition( translated); final boolean invalidEv = Arrays.stream(decomposition.getRealEigenvalues()) .anyMatch(e -> e <= 0.0); if (invalidEv) { return Optional.empty(); } final double[] radii = Arrays.stream(decomposition.getRealEigenvalues()) .map(ev -> Math.sqrt(1.0 / ev)).toArray(); final Ellipsoid ellipsoid = new Ellipsoid(radii[0], radii[1], radii[2]); ellipsoid.setCentroid(center); final Matrix3dc orientation = toOrientationMatrix(decomposition); ellipsoid.setOrientation(orientation); return Optional.of(ellipsoid); }  }
QuadricToEllipsoid extends
	AbstractUnaryFunctionOp<Matrix4dc, Optional<Ellipsoid>> { @Override public Optional<Ellipsoid> calculate(final Matrix4dc quadricSolution) { final Vector3dc center = findCenter(quadricSolution); final Matrix4dc translated = translateToCenter(quadricSolution, center); final EigenDecomposition decomposition = solveEigenDecomposition( translated); final boolean invalidEv = Arrays.stream(decomposition.getRealEigenvalues()) .anyMatch(e -> e <= 0.0); if (invalidEv) { return Optional.empty(); } final double[] radii = Arrays.stream(decomposition.getRealEigenvalues()) .map(ev -> Math.sqrt(1.0 / ev)).toArray(); final Ellipsoid ellipsoid = new Ellipsoid(radii[0], radii[1], radii[2]); ellipsoid.setCentroid(center); final Matrix3dc orientation = toOrientationMatrix(decomposition); ellipsoid.setOrientation(orientation); return Optional.of(ellipsoid); }  @Override Optional<Ellipsoid> calculate(final Matrix4dc quadricSolution); }
QuadricToEllipsoid extends
	AbstractUnaryFunctionOp<Matrix4dc, Optional<Ellipsoid>> { @Override public Optional<Ellipsoid> calculate(final Matrix4dc quadricSolution) { final Vector3dc center = findCenter(quadricSolution); final Matrix4dc translated = translateToCenter(quadricSolution, center); final EigenDecomposition decomposition = solveEigenDecomposition( translated); final boolean invalidEv = Arrays.stream(decomposition.getRealEigenvalues()) .anyMatch(e -> e <= 0.0); if (invalidEv) { return Optional.empty(); } final double[] radii = Arrays.stream(decomposition.getRealEigenvalues()) .map(ev -> Math.sqrt(1.0 / ev)).toArray(); final Ellipsoid ellipsoid = new Ellipsoid(radii[0], radii[1], radii[2]); ellipsoid.setCentroid(center); final Matrix3dc orientation = toOrientationMatrix(decomposition); ellipsoid.setOrientation(orientation); return Optional.of(ellipsoid); }  @Override Optional<Ellipsoid> calculate(final Matrix4dc quadricSolution);  }