Example #1
0
        public void CircleIntersectsSphereTest()
        {
            Point3d  p = new Point3d();
            Circle3d c = new Circle3d(p, 1.0, new Vector3d(0, 0, 1));

            // Intersecting objects
            Sphere s = new Sphere(new Point3d(0, 0, 1), 1.1);

            Assert.IsTrue(c.Intersects(s));

            s = new Sphere(new Point3d(0, 0, 0), 10);
            Assert.IsTrue(c.Intersects(s));

            s = new Sphere(new Point3d(2, 0, 0), 1.1);
            Assert.IsTrue(c.Intersects(s));

            // Touching objects
            s = new Sphere(new Point3d(0, 0, 1), 1.0);
            Assert.IsTrue(c.Intersects(s));

            s = new Sphere(new Point3d(2, 0, 0), 1.0);
            Assert.IsTrue(c.Intersects(s));

            // Non-intersecting objects
            s = new Sphere(new Point3d(3, 0, 0), 1.0);
            Assert.IsFalse(c.Intersects(s));
        }
        public void PlanarObjectsCoplanarityTest()
        {
            Plane3d s1 = new Plane3d(new Point3d(1, 1, 1), new Vector3d(1, 0, 0));
            Plane3d s2 = new Plane3d(new Point3d(-1, 1, 1), new Vector3d(1, 0, 0));
            Plane3d s3 = new Plane3d(new Point3d(1, 2, 3), new Vector3d(-1, 0, 0));
            Plane3d s4 = new Plane3d(new Point3d(1, 1, 1), new Vector3d(-1, 2, 3));

            Assert.IsTrue(s1.IsCoplanarTo(s3));
            Assert.IsTrue(s1.IsCoplanarTo(s1));
            Assert.IsFalse(s1.IsCoplanarTo(s2));
            Assert.IsFalse(s1.IsCoplanarTo(s4));

            Circle3d c = new Circle3d(new Point3d(1, 2, 2), 5, new Vector3d(1, 0, 0));

            Assert.IsTrue(c.IsCoplanarTo(c));
            Assert.IsTrue(s1.IsCoplanarTo(c));
            Assert.IsFalse(s2.IsCoplanarTo(c));
            Assert.IsTrue(c.IsCoplanarTo(s1));
            Assert.IsFalse(c.IsCoplanarTo(s2));

            Triangle t = new Triangle(new Point3d(1, 2, 2), new Point3d(1, -5, 0), new Point3d(1, 3, -2));

            Assert.IsTrue(t.IsCoplanarTo(t));
            Assert.IsTrue(s1.IsCoplanarTo(t));
            Assert.IsFalse(s2.IsCoplanarTo(t));
            Assert.IsTrue(t.IsCoplanarTo(s1));
            Assert.IsFalse(t.IsCoplanarTo(s2));
            Assert.IsTrue(t.IsCoplanarTo(c));
        }
Example #3
0
        public void PointInCircleTest()
        {
            Point3d  p = new Point3d(1, 1, 0);
            Circle3d s = new Circle3d(p, 5, new Vector3d(0, 0, 1));

            p = new Point3d(2, 2, 0);  // Point inside
            Assert.IsTrue(p.BelongsTo(s));
            Assert.IsTrue(p.IsInside(s));
            Assert.IsFalse(p.IsOutside(s));
            Assert.IsFalse(p.IsOnBoundary(s));

            p = new Point3d(1, 6, 0);  // Point on boundary
            Assert.IsTrue(p.BelongsTo(s));
            Assert.IsFalse(p.IsInside(s));
            Assert.IsFalse(p.IsOutside(s));
            Assert.IsTrue(p.IsOnBoundary(s));

            p = new Point3d(1, 6.005, 0);  // Point outside
            Assert.IsFalse(p.BelongsTo(s));
            Assert.IsFalse(p.IsInside(s));
            Assert.IsTrue(p.IsOutside(s));
            Assert.IsFalse(p.IsOnBoundary(s));

            p = new Point3d(1, 2, 0.01);  // Point outside
            Assert.IsFalse(p.BelongsTo(s));
            Assert.IsFalse(p.IsInside(s));
            Assert.IsTrue(p.IsOutside(s));
            Assert.IsFalse(p.IsOnBoundary(s));
        }
Example #4
0
        public void CircleIntersectionWithPlaneTest()
        {
            // parallel obecjts
            Circle3d c = new Circle3d(new Point3d(5, 6, 1), 5, new Vector3d(0, 0, 1));
            Plane3d  s = new Plane3d(new Point3d(0, 0, 0), new Vector3d(0, 0, 1));

            Assert.AreEqual(c.IntersectionWith(s), null);

            // coplanar objects
            s = new Plane3d(new Point3d(0, 0, 1), new Vector3d(0, 0, 1));
            Assert.AreEqual(c.IntersectionWith(s), c);

            // nonintersecting objects
            c = new Circle3d(new Point3d(5, 6, 10), 5, new Vector3d(0, 0, 1));
            s = new Plane3d(new Point3d(0, 0, 1), new Vector3d(0, 0, 1));
            Assert.AreEqual(c.IntersectionWith(s), null);

            // intersection in one point
            c = new Circle3d(new Point3d(0, 0, 3), 5, new Vector3d(3, 0, 4));
            s = new Plane3d(new Point3d(5, 5, 0), new Vector3d(0, 0, 1));
            Assert.AreEqual(c.IntersectionWith(s), new Point3d(4, 0, 0));

            // intersection in two points
            c = new Circle3d(new Point3d(0, 0, 3), 5, new Vector3d(3, 0, 0));
            s = new Plane3d(new Point3d(5, 5, 0), new Vector3d(0, 0, 1));
            Assert.AreEqual(c.IntersectionWith(s), new Segment3d(new Point3d(0, 4, 0), new Point3d(0, -4, 0)));
        }
Example #5
0
        public void CircleIntersectionWithCircle3DTest()
        {
            // Touching circles
            Circle3d c1 = new Circle3d(new Point3d(0, 0, 0), 5, new Vector3d(0, 0, 1));
            Circle3d c2 = new Circle3d(new Point3d(5, 0, 0), 5, new Vector3d(1, 0, 0));

            Assert.AreEqual(c1.IntersectionWith(c2), new Point3d(5, 0, 0));

            // Touching circles
            c2 = new Circle3d(new Point3d(10, 0, 0), 5, new Vector3d(0, 1, 0));
            Assert.AreEqual(c1.IntersectionWith(c2), new Point3d(5, 0, 0));

            // Intersecting circles
            c2 = new Circle3d(new Point3d(0, 0, 0), 5, new Vector3d(0, 1, 0));
            Segment3d s = new Segment3d(new Point3d(-5, 0, 0), new Point3d(5, 0, 0));

            Assert.AreEqual(c1.IntersectionWith(c2), s);

            // Intersecting circles
            c2 = new Circle3d(new Point3d(5, 0, 0), 5, new Vector3d(0, 1, 0));
            s  = new Segment3d(new Point3d(0, 0, 0), new Point3d(5, 0, 0));
            Assert.AreEqual(c1.IntersectionWith(c2), s);

            // Intersecting circles
            c2 = new Circle3d(new Point3d(0, 0, 4), 5, new Vector3d(0, 1, 0));
            s  = new Segment3d(new Point3d(-3, 0, 0), new Point3d(3, 0, 0));
            Assert.AreEqual(c1.IntersectionWith(c2), s);
        }
Example #6
0
        public void CircleIntersectionWithCircle2DTest()
        {
            // parallel obecjts
            Circle3d c1 = new Circle3d(new Point3d(0, 0, 0), 5, new Vector3d(0, 0, 1));
            Circle3d c2 = new Circle3d(new Point3d(5, 0, 1), 5, new Vector3d(0, 0, 1));

            Assert.AreEqual(c1.IntersectionWith(c2), null);

            // Coincided circles
            c2 = new Circle3d(new Point3d(0, 0, 0), 5, new Vector3d(0, 0, 1));
            Assert.AreEqual(c1.IntersectionWith(c2), c1);

            // Separated circles
            c2 = new Circle3d(new Point3d(10, 0, 0), 2, new Vector3d(0, 0, 1));
            Assert.AreEqual(c1.IntersectionWith(c2), null);

            // Outer tangency
            c2 = new Circle3d(new Point3d(10, 0, 0), 5, new Vector3d(0, 0, 1));
            Assert.AreEqual(c1.IntersectionWith(c2), new Point3d(5, 0, 0));

            // Inner tangency 1
            c2 = new Circle3d(new Point3d(3, 0, 0), 2, new Vector3d(0, 0, 1));
            Assert.AreEqual(c1.IntersectionWith(c2), new Point3d(5, 0, 0));

            // Inner tangency 2
            c2 = new Circle3d(new Point3d(-2, 0, 0), 7, new Vector3d(0, 0, 1));
            Assert.AreEqual(c1.IntersectionWith(c2), new Point3d(5, 0, 0));

            // Intersection
            c2 = new Circle3d(new Point3d(6, 0, 0), 5, new Vector3d(0, 0, 1));
            Segment3d s = new Segment3d(new Point3d(3, 4, 0), new Point3d(3, -4, 0));

            Assert.AreEqual(c1.IntersectionWith(c2), s);
        }
Example #7
0
        public void CircleIntersectionWithLineTest()
        {
            // parallel obecjts
            Circle3d c = new Circle3d(new Point3d(0, 0, 0), 5, new Vector3d(0, 0, 1));
            Line3d   l = new Line3d(new Point3d(0, 0, 1), new Vector3d(1, 0, 0));

            Assert.AreEqual(c.IntersectionWith(l), null);

            // nonintersecting objects
            c = new Circle3d(new Point3d(0, 0, 0), 5, new Vector3d(0, 0, 1));
            l = new Line3d(new Point3d(10, 0, 0), new Vector3d(1, 1, 0));
            Assert.AreEqual(c.IntersectionWith(l), null);

            // intersection in one point (touching line)
            c = new Circle3d(new Point3d(0, 0, 0), 5, new Vector3d(0, 0, 1));
            l = new Line3d(new Point3d(5, 0, 0), new Vector3d(0, 1, 0));
            Assert.AreEqual(c.IntersectionWith(l), new Point3d(5, 0, 0));

            // intersection in one point (crossing line)
            c = new Circle3d(new Point3d(0, 0, 0), 5, new Vector3d(0, 0, 1));
            l = new Line3d(new Point3d(1, 1, 0), new Vector3d(0, 0, 1));
            Assert.AreEqual(c.IntersectionWith(l), new Point3d(1, 1, 0));

            // intersection in two points
            c = new Circle3d(new Point3d(0, 0, 0), 5, new Vector3d(0, 0, 1));
            l = new Line3d(new Point3d(0, -4, 0), new Vector3d(1, 0, 0));
            Assert.AreEqual(c.IntersectionWith(l), new Segment3d(new Point3d(-3, -4, 0), new Point3d(3, -4, 0)));
        }
Example #8
0
        public void SphereProjectionToPlaneTest()
        {
            Sphere   s   = new Sphere(new Point3d(-2, -2, -2), 5);
            Plane3d  p   = new Plane3d(new Point3d(1, 1, 1), new Vector3d(1, 1, 1));
            Circle3d c   = s.ProjectionTo(p);
            Circle3d res = new Circle3d(new Point3d(1, 1, 1), 5, new Vector3d(-1, -1, -1));

            Assert.AreEqual(c, res);
        }
Example #9
0
        public void SphereIntersectionWithPlaneTest()
        {
            Sphere   s = new Sphere(new Point3d(1, -1, 3), 3);
            Plane3d  p = new Plane3d(1, 4, 5, 6);
            Circle3d c = (Circle3d)s.IntersectionWith(p);

            Assert.IsTrue(Abs(c.R - 1.13) < 0.005);
            Assert.IsTrue(c.Center.DistanceTo(new Point3d(0.57, -2.71, 0.86)) < 0.01);
        }
Example #10
0
        public void CircleBoundaryDistanceToLineTest()
        {
            Point3d  p = new Point3d();
            Circle3d c = new Circle3d(p, 1.0, new Vector3d(0, 0, 1));
            Point3d  point_on_circle, point_on_line;

            // Parallel objects
            Line3d l    = new Line3d(new Point3d(0, 2, 1), new Vector3d(1, 0, 0));
            double dist = c.DistanceToBoundary(l, out point_on_circle, out point_on_line);

            Assert.AreEqual(dist, Sqrt(2));
            Assert.AreEqual(point_on_circle, new Point3d(0, 1, 0));
            Assert.AreEqual(point_on_line, new Point3d(0, 2, 1));

            l    = new Line3d(new Point3d(0, 1, 1), new Vector3d(1, 0, 0));
            dist = c.DistanceToBoundary(l, out point_on_circle, out point_on_line);
            Assert.AreEqual(dist, 1);
            Assert.AreEqual(point_on_circle, new Point3d(0, 1, 0));
            Assert.AreEqual(point_on_line, new Point3d(0, 1, 1));

            l    = new Line3d(new Point3d(0, 0, 1), new Vector3d(1, 0, 0));
            dist = c.DistanceToBoundary(l, out point_on_circle, out point_on_line);
            Assert.AreEqual(dist, 1);
            Assert.AreEqual(point_on_circle, new Point3d(1, 0, 0));
            Assert.AreEqual(point_on_line, new Point3d(1, 0, 1));

            // Coplanar intersecting objects
            l    = new Line3d(new Point3d(0, 1, 0), new Vector3d(1, 0, 0));
            dist = c.DistanceToBoundary(l, out point_on_circle, out point_on_line);
            Assert.AreEqual(dist, 0);
            Assert.AreEqual(point_on_circle, new Point3d(0, 1, 0));
            Assert.AreEqual(point_on_line, new Point3d(0, 1, 0));


            // Coplanar non-intersecting objects
            l    = new Line3d(new Point3d(0, 2, 0), new Vector3d(1, 0, 0));
            dist = c.DistanceToBoundary(l, out point_on_circle, out point_on_line);
            Assert.AreEqual(dist, 1);
            Assert.AreEqual(point_on_circle, new Point3d(0, 1, 0));
            Assert.AreEqual(point_on_line, new Point3d(0, 2, 0));


            // Intersecting objects
            l    = new Line3d(new Point3d(1, 0, 0), new Vector3d(1, 0, 1));
            dist = c.DistanceToBoundary(l, out point_on_circle, out point_on_line);
            Assert.IsTrue(GeometRi3D.AlmostEqual(dist, 0));
            Assert.AreEqual(point_on_circle, new Point3d(1, 0, 0));
            Assert.AreEqual(point_on_line, new Point3d(1, 0, 0));


            // Non-intersecting objects
            l    = new Line3d(new Point3d(0, 0, 0), new Vector3d(1, 0, 1));
            dist = c.DistanceToBoundary(l, out point_on_circle, out point_on_line);
            Assert.IsTrue(GeometRi3D.AlmostEqual(dist, Sqrt(0.5)));
            Assert.AreEqual(point_on_circle, new Point3d(-1, 0, 0));
            Assert.AreEqual(point_on_line, new Point3d(-0.5, 0, -0.5));
        }
Example #11
0
        public void BoxDistanceToCircleTest()
        {
            Box3d    box = new Box3d();
            Circle3d c   = new Circle3d(new Point3d(-1.3195, -1.0435, -0.70047), 0.35, new Vector3d(0.83694, -0.13208, -0.53112));

            double dist = box.DistanceTo(c);

            Assert.IsTrue(dist > 0);
        }
Example #12
0
        public void BoxIntersectsCircleTest2()
        {
            Box3d    box = new Box3d(new Point3d(0.5, 0.5, 0.5), 1, 1, 1);
            Circle3d c   = new Circle3d(new Point3d(0.957494668177094, 1.08987119472114, -0.11622424522239),
                                        0.154926580712558,
                                        new Vector3d(0.362303959251271, 0.267138656415756, 0.892957322249635));

            Assert.IsFalse(c.Intersects(box));
        }
Example #13
0
        public void CircleIntersectionWithCircle3DTest_6()
        {
            Circle3d c1 = new Circle3d(new Point3d(0.54942463156146, 0.471633229492457, 0.687724718029017), 0.45, new Vector3d(0.00234836551341398, -0.00168595290036738, 0.00407955171963179));
            Circle3d c2 = new Circle3d(new Point3d(0.466918419682331, 0.557604272259504, 0.400167832409575), 0.45, new Vector3d(0.000185747980640577, 0.0018045609707127, 0.00465929795040716));

            Assert.IsTrue(c1.IntersectionWith(c2) != null);
            Assert.IsTrue(c2.IntersectionWith(c1) != null);
            Assert.IsTrue(c1.Intersects(c2));
            Assert.IsTrue(c2.Intersects(c1));
        }
Example #14
0
        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));
        }
Example #15
0
        public void CircleAABBTest()
        {
            Point3d  p = new Point3d(1, 1, 1);
            Vector3d v = new Vector3d(3, 4, 0);
            Circle3d c = new Circle3d(p, 5, v);

            Box3d res = new Box3d(p, 8, 6, 10);

            Assert.AreEqual(c.BoundingBox(), res);
        }
Example #16
0
        public void TriangleIntersectsCircleTest()
        {
            Circle3d c = new Circle3d(new Point3d(), 1.0, new Vector3d(0, 0, 1));

            // Coplanar objects
            // Triangle's vertecx inside circle
            Point3d  p1 = new Point3d(0.5, 0.5, 0);
            Point3d  p2 = new Point3d(2, 3, 0);
            Point3d  p3 = new Point3d(-3, 1, 0);
            Triangle t  = new Triangle(p1, p2, p3);

            Assert.IsTrue(c.Intersects(t));

            // circle's center inside triangle
            p1 = new Point3d(-5, -5, 0);
            p2 = new Point3d(5, -5, 0);
            p3 = new Point3d(0, 5, 0);
            t  = new Triangle(p1, p2, p3);
            Assert.IsTrue(c.Intersects(t));

            // circle touch triangle
            p1 = new Point3d(1, -1, 0);
            p2 = new Point3d(1, 1, 0);
            p3 = new Point3d(3, 0, 0);
            t  = new Triangle(p1, p2, p3);
            Assert.IsTrue(c.Intersects(t));

            // Non-intersecting objects
            p1 = new Point3d(1.5, -1, 0);
            p2 = new Point3d(1.5, 1, 0);
            p3 = new Point3d(3, 0, 0);
            t  = new Triangle(p1, p2, p3);
            Assert.IsFalse(c.Intersects(t));

            // Non-coplanar objects
            p1 = new Point3d(0.5, 0.5, -1);
            p2 = new Point3d(0.5, -0.5, 1);
            p3 = new Point3d(0, 0, 1);
            t  = new Triangle(p1, p2, p3);
            Assert.IsTrue(c.Intersects(t));

            // Non-intersecting objects
            p1 = new Point3d(1.5, -1, -1);
            p2 = new Point3d(1.5, 1, -2);
            p3 = new Point3d(3, 0, -1);
            t  = new Triangle(p1, p2, p3);
            Assert.IsFalse(c.Intersects(t));

            // Non-intersecting objects
            p1 = new Point3d(1, 1, -1);
            p2 = new Point3d(1, 1, -2);
            p3 = new Point3d(1, 5, -1);
            t  = new Triangle(p1, p2, p3);
            Assert.IsFalse(c.Intersects(t));
        }
Example #17
0
        public void CircleBy3PointsTest()
        {
            Point3d p1 = new Point3d(-3, 0, 4);
            Point3d p2 = new Point3d(4, 0, 5);
            Point3d p3 = new Point3d(1, 0, -4);

            Circle3d c = new Circle3d(p1, p2, p3);

            Assert.IsTrue(c.Center == new Point3d(1, 0, 1));
            Assert.IsTrue(Abs(c.R - 5) <= GeometRi3D.Tolerance);
        }
Example #18
0
        public void IsInsideBoxTest()
        {
            Box3d    box = new Box3d();
            Circle3d c   = new Circle3d(new Point3d(0, 0, 0), 0.2, new Vector3d(0, 0, 1));

            Assert.IsTrue(c.IsInside(box));
            c = new Circle3d(new Point3d(5, 0, 0), 0.2, new Vector3d(0, 0, 1));
            Assert.IsFalse(c.IsInside(box));
            c = new Circle3d(new Point3d(0.9, 0, 0), 0.2, new Vector3d(0, 0, 1));
            Assert.IsFalse(c.IsInside(box));
        }
Example #19
0
        public void CircleIntersectionWithRayTest()
        {
            // intersection in one point (crossing ray)
            Circle3d c = new Circle3d(new Point3d(0, 0, 0), 5, new Vector3d(0, 0, 1));
            Ray3d    r = new Ray3d(new Point3d(0, 0, 0), new Vector3d(1, 0, 0));

            Assert.AreEqual(c.IntersectionWith(r), new Segment3d(new Point3d(5, 0, 0), new Point3d(0, 0, 0)));

            // intersection in one point (touching line)
            r = new Ray3d(new Point3d(5, 0, 0), new Vector3d(1, 0, 0));
            Assert.AreEqual(c.IntersectionWith(r), new Point3d(5, 0, 0));
        }
        public void SegmentDistanceToCircleTest()
        {
            Point3d   p1 = new Point3d(-0.5, -0.5, -0.5);
            Point3d   p2 = new Point3d(0.5, 0.5, -0.5);
            Segment3d s  = new Segment3d(p1, p2);

            Circle3d c = new Circle3d(new Point3d(-1.3195, -1.0435, -0.70047), 0.35, new Vector3d(0.83694, -0.13208, -0.53112));

            double dist = s.DistanceTo(c);

            Assert.IsTrue(dist > 0);
        }
Example #21
0
        public void TriangleDistanceToCircleTest()
        {
            Point3d  p1 = new Point3d(-0.5, -0.5, -0.5);
            Point3d  p2 = new Point3d(0.5, 0.5, -0.5);
            Point3d  p3 = new Point3d(0.5, -0.5, -0.5);
            Triangle t  = new Triangle(p1, p2, p3);

            Circle3d c = new Circle3d(new Point3d(-1.3195, -1.0435, -0.70047), 0.35, new Vector3d(0.83694, -0.13208, -0.53112));

            double dist = t.DistanceTo(c);

            Assert.IsTrue(dist > 0);
        }
Example #22
0
        public void SphereIntersectionWithSphereTest()
        {
            Sphere   s1 = new Sphere(new Point3d(-2, 2, 4), 5);
            Sphere   s2 = new Sphere(new Point3d(3, 7, 3), 5);
            Circle3d c1 = (Circle3d)s1.IntersectionWith(s2);

            Assert.IsTrue(Abs(c1.R - 3.5) < GeometRi3D.Tolerance);
            Assert.IsTrue(c1.Center == new Point3d(0.5, 4.5, 3.5));

            Circle3d c2 = (Circle3d)s2.IntersectionWith(s1);

            Assert.IsTrue(c1 == c2);
        }
Example #23
0
        public void Circle3dRelativeToleranceTest()
        {
            Circle3d s1 = new Circle3d(new Point3d(100, 100, 0), 10, new Vector3d(1, 0, 0));
            Circle3d s2 = new Circle3d(new Point3d(100, 100.09, 0), 10, new Vector3d(10, 0.09, 0));

            Assert.AreNotEqual(s1, s2);

            GeometRi3D.Tolerance            = 0.01;
            GeometRi3D.UseAbsoluteTolerance = false;
            Assert.AreEqual(s1, s2);
            GeometRi3D.Tolerance            = 1e-12;
            GeometRi3D.UseAbsoluteTolerance = true;
        }
Example #24
0
        public void CircleToEllipseTest()
        {
            Circle3d c = new Circle3d(new Point3d(5, 6, 1), 5, new Vector3d(3, 0, 1));
            Ellipse  e = c.ToEllipse;

            Assert.IsTrue(c.ParametricForm(0.5).BelongsTo(e));
            Assert.IsTrue(c.ParametricForm(0.725).BelongsTo(e));
            Assert.IsTrue(c.ParametricForm(2.7215).BelongsTo(e));

            Assert.IsTrue(e.ParametricForm(0.5).BelongsTo(c));
            Assert.IsTrue(e.ParametricForm(0.725).BelongsTo(c));
            Assert.IsTrue(e.ParametricForm(2.7215).BelongsTo(c));
        }
Example #25
0
        public void CircleProjectionToPlaneTest()
        {
            Vector3d v1 = new Vector3d(3, 5, 1);
            Circle3d c  = new Circle3d(new Point3d(5, 6, 1), 5, v1);
            Plane3d  s  = new Plane3d(5, 2, 3, -3);

            Point3d p = c.ParametricForm(0.5).ProjectionTo(s);

            Assert.IsTrue(p.BelongsTo(c.ProjectionTo(s)));
            p = c.ParametricForm(0.725).ProjectionTo(s);
            Assert.IsTrue(p.BelongsTo(c.ProjectionTo(s)));
            p = c.ParametricForm(2.7122).ProjectionTo(s);
            Assert.IsTrue(p.BelongsTo(c.ProjectionTo(s)));
        }
Example #26
0
        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));

            // Non-intersecting objects
            l    = new Line3d(new Point3d(0, 1.5, 0), new Vector3d(1, 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));
        }
Example #27
0
        public void IsParallelToTest()
        {
            Vector3d v = new Vector3d(1, 0, 0);
            Line3d   l = new Line3d(new Point3d(), v);
            Ray3d    r = new Ray3d(new Point3d(), v.OrthogonalVector);
            Circle3d c = new Circle3d(new Point3d(), 5, v);

            Assert.IsTrue(v.IsParallelTo(l));
            Assert.IsTrue(l.IsNotParallelTo(r));
            Assert.IsTrue(r.IsOrthogonalTo(v));
            Assert.IsTrue(c.IsOrthogonalTo(l));
            Assert.IsTrue(r.IsParallelTo(c));
            Assert.IsTrue(c.IsParallelTo(Coord3d.GlobalCS.YZ_plane));
            Assert.IsTrue(c.IsOrthogonalTo(Coord3d.GlobalCS.XZ_plane));
            Assert.IsTrue(Coord3d.GlobalCS.YZ_plane.IsOrthogonalTo(v));
        }
Example #28
0
        public void BoxIntersectsCircleTest()
        {
            Box3d    box = new Box3d();
            Circle3d c   = new Circle3d(new Point3d(), 1, new Vector3d(0, 0, 1));

            Assert.IsTrue(c.Intersects(box));

            c = new Circle3d(new Point3d(1.5, 0, 0), 1, new Vector3d(0, 0, 1));
            Assert.IsTrue(c.Intersects(box));

            c = new Circle3d(new Point3d(0.5, 0.5, 0.5), 1, new Vector3d(1, 1, 1));
            Assert.IsTrue(c.Intersects(box));

            c = new Circle3d(new Point3d(0.6, 0.6, 0.6), 1, new Vector3d(1, 1, 1));
            Assert.IsFalse(c.Intersects(box));
        }
Example #29
0
        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));
        }
Example #30
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));
        }