Beispiel #1
0
        public static void Main()
        {
            // Examples of basic operations with GeometRi

            // Global coordinate system is created automatically and can be accessed as "Coord3d.GlobalCS"
            Console.WriteLine("Number of defined coordinate systems: {0}", Coord3d.Counts);
            Console.WriteLine();
            Console.WriteLine("Default coordinate system: ");
            Console.WriteLine(Coord3d.GlobalCS.ToString());



            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("!!! Find intersection of plane with line !!!");

            // Define point and vector in global CS
            Point3d  p1 = new Point3d(1, -5, -1);
            Vector3d v1 = new Vector3d(-2, 3, 4);

            // Define line using point and vector
            Line3d l1 = new Line3d(p1, v1);

            // Define plane using general equation in 3D space in the form "A*x+B*y+C*z+D=0"
            Plane3d s1 = new Plane3d(-2, 2, 3, -29);

            // Find the intersection of line with plane.
            // The results could be point, line or nothing, therefore get result as general object
            // and determine it's type.
            object obj = l1.IntersectionWith(s1);

            if (obj != null)
            {
                if (obj.GetType() == typeof(Line3d))
                {
                    Console.WriteLine("Intersection is line");
                    Line3d l2 = (Line3d)obj;
                    Console.WriteLine(l2.ToString());
                }
                else if (obj.GetType() == typeof(Point3d))
                {
                    Console.WriteLine("Intersection is point");
                    Point3d p2 = (Point3d)obj;
                    Console.WriteLine(p2.ToString());
                }
            }

            // Short variant
            // Will cause "InvalidCastException" if the intersection is not a point
            Point3d p3 = (Point3d)l1.IntersectionWith(s1);

            Console.WriteLine(p3.ToString());



            Console.ReadLine();
        }
Beispiel #2
0
        public void LineIntersectionWithLineTest()
        {
            Line3d l1 = new Line3d(new Point3d(), new Vector3d(1, 0, 0));
            Line3d l2 = new Line3d(new Point3d(8, 0, 0), new Vector3d(-5, 0, 0));

            Assert.IsTrue((Line3d)l1.IntersectionWith(l2) == l1);

            l2 = new Line3d(new Point3d(5, 5, 0), new Vector3d(1, -1, 0));
            Assert.IsTrue((Point3d)l1.IntersectionWith(l2) == new Point3d(10, 0, 0));

            l2 = new Line3d(new Point3d(5, 5, 1), new Vector3d(1, -1, 0));
            Assert.IsTrue((Object)l1.IntersectionWith(l2) == null);
        }
Beispiel #3
0
        public void LineIntersectionWithPlaneTest()
        {
            Point3d  p1 = new Point3d(1, -5, -1);
            Vector3d v1 = new Vector3d(-2, 3, 4);
            Line3d   l1 = new Line3d(p1, v1);
            Plane3d  s1 = new Plane3d(-2, 2, 3, -29);

            Assert.IsTrue((Point3d)l1.IntersectionWith(s1) == new Point3d(-3, 1, 7));
        }
Beispiel #4
0
        public void LineProjectionToPlaneTest()
        {
            Point3d  p1 = new Point3d(1, -5, -1);
            Vector3d v1 = new Vector3d(-2, 3, 4);
            Line3d   l1 = new Line3d(p1, v1);
            Plane3d  s1 = new Plane3d(-2, 2, 3, -29);

            Point3d p2 = (Point3d)l1.IntersectionWith(s1);
            Line3d  l2 = (Line3d)l1.ProjectionTo(s1);

            Assert.IsTrue(p2.BelongsTo(l2));
        }
Beispiel #5
0
        public void LineIntersectionWithPlaneTest3()
        {
            // Line lies in the plane
            Point3d  p1 = new Point3d(1, 0, 0);
            Vector3d v1 = new Vector3d(1, 1, 1);
            Plane3d  s1 = new Plane3d(p1, v1);

            p1 = new Point3d(0, 1, 0);
            Point3d p2 = new Point3d(0, 0, 1);
            Line3d  l1 = new Line3d(p1, new Vector3d(p1, p2));

            Assert.IsTrue((Line3d)l1.IntersectionWith(s1) == l1);
        }
Beispiel #6
0
        public void LineIntersectionWithPlaneTest2()
        {
            // Parallel line
            Point3d  p1 = new Point3d(1, 0, 0);
            Vector3d v1 = new Vector3d(1, 1, 1);
            Plane3d  s1 = new Plane3d(p1, v1);

            p1 = new Point3d(0, 2, 0);
            Point3d p2 = new Point3d(0, 0, 2);
            Line3d  l1 = new Line3d(p1, new Vector3d(p1, p2));

            Assert.IsTrue(l1.IntersectionWith(s1) == null);
        }
Beispiel #7
0
        public void LineConvertToTest()
        {
            Coord3d coord1 = Coord3d.GlobalCS.Copy();
            Coord3d coord2 = Coord3d.GlobalCS.Copy();

            coord2.RotateDeg(new Vector3d(1, 1, 1), 120);

            Point3d  p1 = new Point3d(1, 2, 3, coord1);
            Vector3d v1 = new Vector3d(0, 0, 1);
            Line3d   l1 = new Line3d(p1, v1);

            l1.Point = l1.Point.ConvertTo(coord2);
            Plane3d s1 = coord2.XZ_plane;

            s1.Point = s1.Point.ConvertTo(coord1);

            Assert.IsTrue((Point3d)l1.IntersectionWith(s1) == new Point3d(1, 2, 0));
        }