public void CircleDistanceToCircleTest() { Circle3d c1 = new Circle3d(new Point3d(0, 0, 0), 5, new Vector3d(0, 0, 1)); Circle3d c2 = new Circle3d(new Point3d(11, 0, 0), 5, new Vector3d(0, 0, 1)); Assert.IsTrue(GeometRi3D.AlmostEqual(c1.DistanceTo(c2), 1)); c2 = new Circle3d(new Point3d(11, 0, 0), 5, new Vector3d(0, 2, 1)); Assert.IsTrue(GeometRi3D.AlmostEqual(c1.DistanceTo(c2), 1)); }
public void CircleDistanceToPointTest() { Circle3d c = new Circle3d(new Point3d(0, 0, 0), 5, new Vector3d(0, 0, 1)); Point3d p = new Point3d(2, 3, 4); Assert.IsTrue(GeometRi3D.AlmostEqual(c.DistanceTo(p), 4)); p = new Point3d(4, 3, 0); Assert.IsTrue(GeometRi3D.AlmostEqual(c.DistanceTo(p), 0)); p = new Point3d(2, 3, 0); Assert.IsTrue(GeometRi3D.AlmostEqual(c.DistanceTo(p), 0)); p = new Point3d(8, 0, 4); Assert.IsTrue(GeometRi3D.AlmostEqual(c.DistanceTo(p), 5)); }
public void CircleDistanceToLineTest() { Point3d p = new Point3d(); Circle3d c = new Circle3d(p, 1.0, new Vector3d(0, 0, 1)); Point3d p1, p2; // Parallel objects Line3d l = new Line3d(new Point3d(0, 0, 1), new Vector3d(1, 0, 0)); double dist = c.DistanceTo(l, out p1, out p2); Assert.AreEqual(dist, 1.0); Assert.AreEqual(p1, p); Assert.AreEqual(p2, new Point3d(0, 0, 1)); // Coplanar intersecting objects l = new Line3d(new Point3d(0, 0.5, 0), new Vector3d(1, 0, 0)); dist = c.DistanceTo(l, out p1, out p2); Assert.AreEqual(dist, 0.0); Assert.AreEqual(p1, new Point3d(0, 0.5, 0)); Assert.AreEqual(p2, new Point3d(0, 0.5, 0)); // Coplanar non-intersecting objects l = new Line3d(new Point3d(0, 1.5, 0), new Vector3d(1, 0, 0)); dist = c.DistanceTo(l, out p1, out p2); Assert.AreEqual(dist, 0.5); Assert.AreEqual(p1, new Point3d(0, 1, 0)); Assert.AreEqual(p2, new Point3d(0, 1.5, 0)); // Intersecting objects l = new Line3d(new Point3d(0, 0.5, 0), new Vector3d(0, 0, 1)); dist = c.DistanceTo(l, out p1, out p2); Assert.AreEqual(dist, 0.0); Assert.AreEqual(p1, new Point3d(0, 0.5, 0)); Assert.AreEqual(p2, new Point3d(0, 0.5, 0)); // Non-intersecting objects l = new Line3d(new Point3d(0, 1.5, 0), new Vector3d(0, 0, 1)); dist = c.DistanceTo(l, out p1, out p2); Assert.AreEqual(dist, 0.5); Assert.AreEqual(p1, new Point3d(0, 1, 0)); Assert.AreEqual(p2, new Point3d(0, 1.5, 0)); }
public void CircleDistanceToPlaneTest() { // Parallel circle Plane3d p = new Plane3d(new Point3d(), new Vector3d(0, 0, 1)); Circle3d c = new Circle3d(new Point3d(10, 10, 10), 5, new Vector3d(0, 0, 1)); Assert.IsTrue(GeometRi3D.AlmostEqual(c.DistanceTo(p), 10)); // Orthogonal circle c = new Circle3d(new Point3d(10, 10, 10), 5, new Vector3d(1, 1, 0)); Assert.IsTrue(GeometRi3D.AlmostEqual(c.DistanceTo(p), 5)); // Inclined circle c = new Circle3d(new Point3d(10, 10, 10), 5, new Vector3d(3, 0, 4)); Assert.IsTrue(GeometRi3D.AlmostEqual(c.DistanceTo(p), 7)); }
public void CircleToCircleClosestPointTest() { Point3d p1, p2; // Nonintersecting circles in one plane Circle3d c1 = new Circle3d(new Point3d(0, 0, 0), 5, new Vector3d(0, 0, 1)); Circle3d c2 = new Circle3d(new Point3d(11, 0, 0), 5, new Vector3d(0, 0, 1)); double dist = c1.DistanceTo(c2, out p1, out p2); Assert.IsTrue(GeometRi3D.AlmostEqual(dist, p1.DistanceTo(p2))); // Intersecting circles in one plane c1 = new Circle3d(new Point3d(0, 0, 0), 5, new Vector3d(0, 0, 1)); c2 = new Circle3d(new Point3d(8, 0, 0), 5, new Vector3d(0, 0, 1)); dist = c1.DistanceTo(c2, out p1, out p2); Assert.IsTrue(GeometRi3D.AlmostEqual(dist, p1.DistanceTo(p2))); // Intersecting circles in one plane c1 = new Circle3d(new Point3d(0, 0, 0), 5, new Vector3d(0, 0, 1)); c2 = new Circle3d(new Point3d(0, 0, 0), 3, new Vector3d(0, 0, 1)); dist = c1.DistanceTo(c2, out p1, out p2); Assert.IsTrue(GeometRi3D.AlmostEqual(dist, p1.DistanceTo(p2))); // Touching circles c1 = new Circle3d(new Point3d(0, 0, 0), 5, new Vector3d(0, 0, 1)); c2 = new Circle3d(new Point3d(8, 0, 0), 3, new Vector3d(0, 0, 1)); dist = c1.DistanceTo(c2, out p1, out p2); Assert.IsTrue(GeometRi3D.AlmostEqual(dist, p1.DistanceTo(p2))); // Coplanar circles c1 = new Circle3d(new Point3d(0, 0, 0), 5, new Vector3d(0, 0, 1)); c2 = new Circle3d(new Point3d(5, 0, 5), 3, new Vector3d(0, 0, 1)); dist = c1.DistanceTo(c2, out p1, out p2); Assert.IsTrue(GeometRi3D.AlmostEqual(dist, p1.DistanceTo(p2))); // Coplanar circles c1 = new Circle3d(new Point3d(0, 0, 0), 5, new Vector3d(0, 0, 1)); c2 = new Circle3d(new Point3d(15, 0, 5), 3, new Vector3d(0, 0, 1)); dist = c1.DistanceTo(c2, out p1, out p2); Assert.IsTrue(GeometRi3D.AlmostEqual(dist, p1.DistanceTo(p2))); // Random circles c1 = new Circle3d(new Point3d(2, 3, 0), 5, new Vector3d(4, -2, 1)); c2 = new Circle3d(new Point3d(15, 7, 5), 3, new Vector3d(2, 3, 1)); dist = c1.DistanceTo(c2, out p1, out p2); Assert.IsTrue(GeometRi3D.AlmostEqual(dist, p1.DistanceTo(p2))); }
public void CircleClosestPointToPlaneTest() { Point3d p = new Point3d(0, 0, 5); Circle3d c = new Circle3d(p, 1.0, new Vector3d(0, 0, 1)); Plane3d plane = new Plane3d(new Point3d(), new Vector3d(0, 0, 1)); Point3d p1, p2; // Parallel objects double dist = c.DistanceTo(plane, out p1, out p2); Assert.AreEqual(dist, 5.0); Assert.AreEqual(p1, p); Assert.AreEqual(p2, new Point3d(0, 0, 0)); // Non-parallel objects c = new Circle3d(p, 1.0, new Vector3d(1, 0, 0)); dist = c.DistanceTo(plane, out p1, out p2); Assert.AreEqual(dist, 4.0); Assert.AreEqual(p1, new Point3d(0, 0, 4)); Assert.AreEqual(p2, new Point3d(0, 0, 0)); }
public void CircleClosestPointToTriangleTest() { Point3d p1 = new Point3d(0, 0, 0); Point3d p2 = new Point3d(5, 0, 0); Point3d p3 = new Point3d(0, 5, 0); Triangle t = new Triangle(p1, p2, p3); Point3d pc, pt; // Circle in triangle Circle3d c = new Circle3d(new Point3d(2, 2, 0), 1, new Vector3d(0, 0, 1)); double dist = c.DistanceTo(t, out pc, out pt); Assert.AreEqual(dist, 0.0); Assert.AreEqual(pc, new Point3d(2, 2, 0)); Assert.AreEqual(pt, new Point3d(2, 2, 0)); // Triangle in circle c = new Circle3d(new Point3d(5, 5, 0), 10, new Vector3d(0, 0, 1)); dist = c.DistanceTo(t, out pc, out pt); Assert.AreEqual(dist, 0.0); Assert.AreEqual(pc, pt); Assert.IsTrue(pc.BelongsTo(c)); Assert.IsTrue(pt.BelongsTo(t)); // Closest point at vertex c = new Circle3d(new Point3d(-2, -2, 0), Sqrt(2), new Vector3d(0, 0, 1)); dist = c.DistanceTo(t, out pc, out pt); Assert.AreEqual(dist, Sqrt(2.0)); Assert.AreEqual(pc, new Point3d(-1, -1, 0)); Assert.AreEqual(pt, p1); // Closest point at edge c = new Circle3d(new Point3d(2, -2, 0), 1, new Vector3d(0, 0, 1)); dist = c.DistanceTo(t, out pc, out pt); Assert.AreEqual(dist, 1.0); Assert.AreEqual(pc, new Point3d(2, -1, 0)); Assert.AreEqual(pt, new Point3d(2, 0, 0)); }
public void CircleDistanceToSphereTest() { Point3d p = new Point3d(); Circle3d c = new Circle3d(p, 1.0, new Vector3d(0, 0, 1)); Point3d p1, p2; // Intersecting objects Sphere s = new Sphere(new Point3d(0, 0, 1), 1.1); double dist = c.DistanceTo(s, out p1, out p2); Assert.AreEqual(dist, 0.0); Assert.AreEqual(p1, new Point3d(0, 0, 0)); Assert.AreEqual(p2, new Point3d(0, 0, -0.1)); s = new Sphere(new Point3d(0, 0, 0), 10); Assert.AreEqual(c.DistanceTo(s), 0.0); s = new Sphere(new Point3d(2, 0, 0), 1.1); dist = c.DistanceTo(s, out p1, out p2); Assert.AreEqual(dist, 0.0); Assert.AreEqual(p1, new Point3d(1, 0, 0)); Assert.AreEqual(p2, new Point3d(0.9, 0, 0)); // Touching objects s = new Sphere(new Point3d(0, 0, 1), 1.0); dist = c.DistanceTo(s, out p1, out p2); Assert.AreEqual(dist, 0.0); Assert.AreEqual(p1, new Point3d(0, 0, 0)); Assert.AreEqual(p2, new Point3d(0, 0, 0)); s = new Sphere(new Point3d(2, 0, 0), 1.0); dist = c.DistanceTo(s, out p1, out p2); Assert.AreEqual(dist, 0.0); Assert.AreEqual(p1, new Point3d(1, 0, 0)); Assert.AreEqual(p2, new Point3d(1, 0, 0)); // Non-intersecting objects s = new Sphere(new Point3d(3, 0, 0), 1.0); dist = c.DistanceTo(s, out p1, out p2); Assert.IsTrue(GeometRi3D.AlmostEqual(dist, 1.0)); Assert.AreEqual(p1, new Point3d(1, 0, 0)); Assert.AreEqual(p2, new Point3d(2, 0, 0)); }