EllipsoidOptimisationStrategy extends AbstractBinaryFunctionOp<byte[][], Vector3d, QuickEllipsoid> { static void wiggle(QuickEllipsoid ellipsoid) { final double b = Math.random() * 0.2 - 0.1; final double c = Math.random() * 0.2 - 0.1; final double a = Math.sqrt(1 - b * b - c * c); final double k = Math.sqrt(a*a+b*b+c*c); final double[] zerothColumn = {a, b, c}; final double[] firstColumn = {-b/k, a/k, 0}; final double[] secondColumn = norm(new double[]{-a*c, -b*c, a*a+b*b}); double[][] rotation = { {zerothColumn[0], firstColumn[0], secondColumn[0]}, {zerothColumn[1], firstColumn[1], secondColumn[1]}, {zerothColumn[2], firstColumn[2], secondColumn[2]} }; ellipsoid.rotate(rotation); }  @Override QuickEllipsoid calculate(byte[][] pixels, Vector3d seedPoint);  }
@Test public void testWiggleSurfacePoint() { double[] radii = {1,2,3}; double[] centre = {0,0,0}; QuickEllipsoid e = new QuickEllipsoid(radii,centre,new double[][]{{1,0,0},{0,1,0},{0,0,1}}); final AnchorEllipsoidConstrain anchorConstrain = new AnchorEllipsoidConstrain(); anchorConstrain.preConstrain(e, new Vector3d(1,0,0)); EllipsoidOptimisationStrategy.wiggle(e); anchorConstrain.postConstrain(e); assertTrue("Wiggle does not preserve surface point.",onSurface(e, new double[]{1,0,0})); }