Ellipsoid { public boolean contains(final double x, final double y, final double z) { final double vx = x - cx; final double vy = y - cy; final double vz = z - cz; final double[] radii = getSortedRadii(); final double maxRadius = radii[2]; if (Math.abs(vx) > maxRadius || Math.abs(vy) > maxRadius || Math.abs( vz) > maxRadius) return false; final double length = Math.sqrt(vx * vx + vy * vy + vz * vz); if (length > maxRadius) return false; if (length <= radii[0]) return true; final double[][] h = eh; final double dot0 = vx * h[0][0] + vy * h[1][0] + vz * h[2][0]; final double dot1 = vx * h[0][1] + vy * h[1][1] + vz * h[2][1]; final double dot2 = vx * h[0][2] + vy * h[1][2] + vz * h[2][2]; final double dot = dot0 * vx + dot1 * vy + dot2 * vz; return dot <= 1; } Ellipsoid(final Object[] ellipsoid);  Ellipsoid(final double a, final double b, final double c,
		final double cx, final double cy, final double cz,
		final double[][] eigenVectors); boolean contains(final double x, final double y, final double z); void contract(final double increment); Ellipsoid copy(); void dilate(final double da, final double db, final double dc); double[] getAxisAlignedBoundingBox(); double[] getCentre(); double[] getRadii(); double[][] getRotation(); void setRotation(final double[][] rotation); double[] getSortedRadii(); double[][] getSurfacePoints(final int nPoints); double[][] getSurfacePoints(final double[][] vectors); double getVolume(); double[] getYMinAndMax(); double[] getZMinAndMax(); void rotate(final double[][] rotation); void setCentroid(final double x, final double y, final double z); static double[][] transpose(final double[][] a); public int id; }
@Test public void testContains() { final double[][] points = unitSphere.getSurfacePoints(1000); assertTrue(unitSphere.contains(0, 0, 0)); for (final double[] v : points) { final double rand = Math.random(); final double x = v[0] * rand; final double y = v[1] * rand; final double z = v[2] * rand; assertTrue("Testing (" + x + ", " + y + ", " + z + ")", unitSphere.contains(x, y, z)); } for (final double[] v : points) { final double rand = Math.random(); final double x = v[0] / rand; final double y = v[1] / rand; final double z = v[2] / rand; assertTrue("Testing (" + x + ", " + y + ", " + z + ")", !unitSphere.contains(x, y, z)); } assertTrue("Testing centroid (1, 2, 3)", oneTwoThree.contains(1, 2, 3)); final double[][] vectors = Vectors.randomVectors(1000); for (final double[] v : vectors) { final double x = v[0] * 18; final double y = v[1] * 18; final double z = v[2] * 18; assertTrue(!threeFiveSeventeen.contains(x, y, z)); } for (final double[] v : vectors) { final double x = v[0] * 2; final double y = v[1] * 2; final double z = v[2] * 2; assertTrue(threeFiveSeventeen.contains(x, y, z)); } final double[][] pointsU = unitSphereTrans.getSurfacePoints(1000); for (final double[] v : pointsU) { final double rand = Math.random(); final double x = 17 + (v[0] - 17) * rand; final double y = 31 + (v[1] - 31) * rand; final double z = 71 + (v[2] - 71) * rand; assertTrue(unitSphereTrans.contains(x, y, z)); } for (final double[] v : pointsU) { final double rand = Math.random(); final double x = 17 + (v[0] - 17) / rand; final double y = 31 + (v[1] - 31) / rand; final double z = 71 + (v[2] - 71) / rand; assertTrue(!unitSphereTrans.contains(x, y, z)); } final double[][] points4 = rotated.getSurfacePoints(1000); for (final double[] p : points4) { final double rand = Math.random(); final double x = p[0] * rand; final double y = p[1] * rand; final double z = p[2] * rand; assertTrue(rotated.contains(x, y, z)); } for (final double[] p : points4) { final double rand = Math.random() * 0.5; final double x = p[0] / rand; final double y = p[1] / rand; final double z = p[2] / rand; assertTrue(!rotated.contains(x, y, z)); } final double[][] points3 = seventeenFiveThree.getSurfacePoints(1000); for (final double[] p : points3) { final double rand = Math.random(); final double x = p[0] * rand; final double y = p[1] * rand; final double z = p[2] * rand; assertTrue(seventeenFiveThree.contains(x, y, z)); } for (final double[] p : points3) { final double rand = Math.random() * 0.1; final double x = p[0] / rand; final double y = p[1] / rand; final double z = p[2] / rand; assertTrue(!seventeenFiveThree.contains(x, y, z)); } final double[][] points2 = threeFiveSeventeen.getSurfacePoints(1000); for (final double[] p : points2) { final double rand = Math.random(); final double x = p[0] * rand; final double y = p[1] * rand; final double z = p[2] * rand; assertTrue(threeFiveSeventeen.contains(x, y, z)); } for (final double[] p : points2) { final double rand = Math.random() / 3; final double x = p[0] / rand; final double y = p[1] / rand; final double z = p[2] / rand; assertTrue(!threeFiveSeventeen.contains(x, y, z)); } }