예제 #1
0
        public void EllipsoidIntersectionWithSegmentRelativeTest()
        {
            double tol  = GeometRi3D.Tolerance;
            bool   mode = GeometRi3D.UseAbsoluteTolerance;

            GeometRi3D.Tolerance            = 0.01;
            GeometRi3D.UseAbsoluteTolerance = false;

            Point3d   p  = new Point3d(0, 0, 0);
            Vector3d  v1 = new Vector3d(4, 0, 0);
            Vector3d  v2 = new Vector3d(0, 6, 0);
            Vector3d  v3 = new Vector3d(0, 0, 9);
            Ellipsoid e  = new Ellipsoid(p, v1, v2, v3);

            Segment3d s = new Segment3d(new Point3d(-5, 0.01, 0), new Point3d(5, 0, 0));

            Assert.IsTrue((Segment3d)e.IntersectionWith(s) == new Segment3d(new Point3d(-4, 0, 0), new Point3d(4, 0, 0)));

            s = new Segment3d(new Point3d(0, -7, 0), new Point3d(0.01, 7, 0));
            Assert.IsTrue((Segment3d)e.IntersectionWith(s) == new Segment3d(new Point3d(0, -6, 0), new Point3d(0, 6, 0)));

            s = new Segment3d(new Point3d(0, 0, 0), new Point3d(0.01, 0, 10));
            Assert.IsTrue((Segment3d)e.IntersectionWith(s) == new Segment3d(new Point3d(0, 0, 0), new Point3d(0, 0, 9)));

            // Resore initial state
            GeometRi3D.UseAbsoluteTolerance = mode;
            GeometRi3D.Tolerance            = tol;
        }
예제 #2
0
        public void EllipsoidIntersectionWithLineTest()
        {
            Point3d   p  = new Point3d(0, 0, 0);
            Vector3d  v1 = new Vector3d(4, 0, 0);
            Vector3d  v2 = new Vector3d(0, 6, 0);
            Vector3d  v3 = new Vector3d(0, 0, 9);
            Ellipsoid e  = new Ellipsoid(p, v1, v2, v3);


            Line3d l = new Line3d(new Point3d(0, 0, 0), v1 = new Vector3d(1, 0, 0));

            Assert.IsTrue((Segment3d)e.IntersectionWith(l) == new Segment3d(new Point3d(-4, 0, 0), new Point3d(4, 0, 0)));

            l = new Line3d(new Point3d(0, 0, 0), v1 = new Vector3d(0, 1, 0));
            Assert.IsTrue((Segment3d)e.IntersectionWith(l) == new Segment3d(new Point3d(0, -6, 0), new Point3d(0, 6, 0)));

            l = new Line3d(new Point3d(0, 0, 0), v1 = new Vector3d(0, 0, 1));
            Assert.IsTrue((Segment3d)e.IntersectionWith(l) == new Segment3d(new Point3d(0, 0, -9), new Point3d(0, 0, 9)));


            p  = new Point3d(0, 2, 1);
            v1 = new Vector3d(-1, 1, 3);
            l  = new Line3d(p, v1);

            Segment3d s = (Segment3d)e.IntersectionWith(l);

            Assert.IsTrue(s.P1.IsOnBoundary(e));
            Assert.IsTrue(s.P2.IsOnBoundary(e));
        }
예제 #3
0
        public void EllipsoidProjectionToLineTest_2()
        {
            Point3d   p  = new Point3d(0, 0, 0);
            Vector3d  v1 = new Vector3d(4, 0, 0);
            Vector3d  v2 = new Vector3d(0, 6, 0);
            Vector3d  v3 = new Vector3d(0, 0, 9);
            Ellipsoid e  = new Ellipsoid(p, v1, v2, v3);

            p  = new Point3d(1, 1, 1);
            v1 = new Vector3d(1, 1, 3);
            Line3d    l = new Line3d(p, v1);
            Segment3d s = e.ProjectionTo(l);

            // Construct plane orthogonal to line and passing through segment end point
            // And check if it is touching ellipsoid
            Plane3d pl1 = new Plane3d(s.P1, v1);
            object  obj = e.IntersectionWith(pl1);

            if (obj.GetType() == typeof(Point3d))
            {
                p = (Point3d)obj;
                if (p.BelongsTo(e))
                {
                    Assert.IsTrue(true);
                }
                else
                {
                    Assert.Fail();
                }
            }
            else
            {
                Assert.Fail();
            }
        }
예제 #4
0
        public void EllipsoidAABBTest()
        {
            Point3d   p  = new Point3d(0, 0, 0);
            Vector3d  v1 = new Vector3d(3, 0, 0);
            Vector3d  v2 = new Vector3d(0, 2, 0);
            Vector3d  v3 = new Vector3d(0, 0, 4);
            Ellipsoid e  = new Ellipsoid(p, v1, v2, v3);
            Rotation  r  = new Rotation(new Vector3d(1, 2, 3), PI / 4);

            e = e.Rotate(r, p);

            Box3d b = e.BoundingBox();

            Plane3d s = new Plane3d(b.P1, b.P2, b.P3);

            Assert.IsTrue(e.IntersectionWith(s).GetType() == typeof(Point3d));

            s = new Plane3d(b.P8, b.P7, b.P6);
            Assert.IsTrue(e.IntersectionWith(s).GetType() == typeof(Point3d));

            s = new Plane3d(b.P1, b.P2, b.P5);
            Assert.IsTrue(e.IntersectionWith(s).GetType() == typeof(Point3d));

            s = new Plane3d(b.P2, b.P3, b.P6);
            Assert.IsTrue(e.IntersectionWith(s).GetType() == typeof(Point3d));

            s = new Plane3d(b.P3, b.P4, b.P7);
            Assert.IsTrue(e.IntersectionWith(s).GetType() == typeof(Point3d));

            s = new Plane3d(b.P1, b.P4, b.P8);
            Assert.IsTrue(e.IntersectionWith(s).GetType() == typeof(Point3d));
        }
예제 #5
0
        public void EllipsoidIntersectionWithLineTest()
        {
            Point3d   p  = new Point3d(0, 0, 0);
            Vector3d  v1 = new Vector3d(4, 0, 0);
            Vector3d  v2 = new Vector3d(0, 6, 0);
            Vector3d  v3 = new Vector3d(0, 0, 9);
            Ellipsoid e  = new Ellipsoid(p, v1, v2, v3);

            p  = new Point3d(0, 2, 1);
            v1 = new Vector3d(-1, 1, 3);
            Line3d l = new Line3d(p, v1);

            Segment3d s = (Segment3d)e.IntersectionWith(l);

            Assert.IsTrue(s.P1.BelongsTo(e));
            Assert.IsTrue(s.P2.BelongsTo(e));
        }
예제 #6
0
        public void EllipsoidIntersectionWithPlaneTest()
        {
            Point3d   p  = new Point3d(0, 0, 0);
            Vector3d  v1 = new Vector3d(5, 0, 0);
            Vector3d  v2 = new Vector3d(0, 4, 0);
            Vector3d  v3 = new Vector3d(0, 0, 3);
            Ellipsoid e  = new Ellipsoid(p, v1, v2, v3);

            Plane3d s = new Plane3d(1, 2, 3, 4);

            Ellipse res = (Ellipse)e.IntersectionWith(s);

            Assert.IsTrue(res.Center.IsInside(e));
            Assert.IsTrue(res.Center.Translate(res.MajorSemiaxis).BelongsTo(e));
            Assert.IsTrue(res.Center.Translate(res.MinorSemiaxis).BelongsTo(e));
            Assert.IsTrue(res.Center.Translate(-res.MajorSemiaxis).BelongsTo(e));
            Assert.IsTrue(res.Center.Translate(-res.MinorSemiaxis).BelongsTo(e));
            Assert.IsTrue(res.ParametricForm(0.01).BelongsTo(e));
            Assert.IsTrue(res.ParametricForm(0.11).BelongsTo(e));
            Assert.IsTrue(res.ParametricForm(0.55).BelongsTo(e));
            Assert.IsTrue(res.ParametricForm(0.876).BelongsTo(e));
        }