Line implements Embedding<Euclidean3D, Euclidean1D> { public double distance(final Vector3D p) { final Vector3D d = p.subtract(zero); final Vector3D n = new Vector3D(1.0, d, -d.dotProduct(direction), direction); return n.getNorm(); } Line(final Vector3D p1, final Vector3D p2, final double tolerance);  Line(final Line line); @Deprecated  Line(final Vector3D p1, final Vector3D p2); void reset(final Vector3D p1, final Vector3D p2); double getTolerance(); Line revert(); Vector3D getDirection(); Vector3D getOrigin(); double getAbscissa(final Vector3D point); Vector3D pointAt(final double abscissa); Vector1D toSubSpace(Vector<Euclidean3D> vector); Vector3D toSpace(Vector<Euclidean1D> vector); Vector1D toSubSpace(final Point<Euclidean3D> point); Vector3D toSpace(final Point<Euclidean1D> point); boolean isSimilarTo(final Line line); boolean contains(final Vector3D p); double distance(final Vector3D p); double distance(final Line line); Vector3D closestPoint(final Line line); Vector3D intersection(final Line line); SubLine wholeLine();  }
@Test public void testPointDistance() throws MathIllegalArgumentException { Line l = new Line(new Vector3D(0, 1, 1), new Vector3D(0, 2, 2), 1.0e-10); Assert.assertEquals(FastMath.sqrt(3.0 / 2.0), l.distance(new Vector3D(1, 0, 1)), 1.0e-10); Assert.assertEquals(0, l.distance(new Vector3D(0, -4, -4)), 1.0e-10); }
@Test public void testLineDistance() throws MathIllegalArgumentException { Line l = new Line(new Vector3D(0, 1, 1), new Vector3D(0, 2, 2), 1.0e-10); Assert.assertEquals(1.0, l.distance(new Line(new Vector3D(1, 0, 1), new Vector3D(1, 0, 2), 1.0e-10)), 1.0e-10); Assert.assertEquals(0.5, l.distance(new Line(new Vector3D(-0.5, 0, 0), new Vector3D(-0.5, -1, -1), 1.0e-10)), 1.0e-10); Assert.assertEquals(0.0, l.distance(l), 1.0e-10); Assert.assertEquals(0.0, l.distance(new Line(new Vector3D(0, -4, -4), new Vector3D(0, -5, -5), 1.0e-10)), 1.0e-10); Assert.assertEquals(0.0, l.distance(new Line(new Vector3D(0, -4, -4), new Vector3D(0, -3, -4), 1.0e-10)), 1.0e-10); Assert.assertEquals(0.0, l.distance(new Line(new Vector3D(0, -4, -4), new Vector3D(1, -4, -4), 1.0e-10)), 1.0e-10); Assert.assertEquals(FastMath.sqrt(8), l.distance(new Line(new Vector3D(0, -4, 0), new Vector3D(1, -4, 0), 1.0e-10)), 1.0e-10); }