public static List<Path> LoadPath()
        {
            Path path = new Path();
            List<Path> pathList = new List<Path>();

            using (StreamReader reader = new StreamReader(@"../../LoadPath.txt"))
            {
                string line = reader.ReadLine();

                while (line != null)
                {
                    if (line != "END OF PATH")
                    {
                        Point3D point = new Point3D();
                        string[] coordinates = line.Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries);
                        point.X = int.Parse(coordinates[0]);
                        point.Y = int.Parse(coordinates[1]);
                        point.Z = int.Parse(coordinates[2]);
                        path.AddPoint(point);
                    }
                    else
                    {
                        pathList.Add(path);
                        path = new Path();
                    }
                    line = reader.ReadLine();
                }
            }
            return pathList;
        }
Пример #2
0
        static void Main()
        {
            Point3D firstPoint = new Point3D(5, 8, -4);
            Point3D secondPoint = new Point3D(1, 1, 3);

            //Test method ToString and method CalculateDistance
            Console.WriteLine("Distance between {0} and {1} is: {2:0.00}", firstPoint, secondPoint, Distance.CalculateDistance(firstPoint, secondPoint));

            //Test (0,0,0)
            Console.WriteLine(Point3D.ZeroPoint);
            Console.WriteLine();

            //Test method SavePath
            Path testPath = new Path();
            testPath.AddPoint(firstPoint);
            testPath.AddPoint(secondPoint);
            PathStorage.SavePath(testPath);

            //Test method LoadPath and print result
            List<Path> testList = PathStorage.LoadPath();
            foreach (var path in testList)
            {
                foreach (var point in path.Points)
                {
                    Console.WriteLine(point);
                }
            }
        }
Пример #3
0
        public static double CalcDistance(Point3D p1, Point3D p2)
        {
            double dx = p1.X - p2.X;
            double dy = p1.Y - p2.Y;
            double dz = p1.Z - p2.Z;

            double d = (double) Math.Sqrt(dx * dx + dy * dy + dz * dz);
            return d;
        }
Пример #4
0
 // Method for loading paths from a text file
 public static List<Path> LoadPath()
 {
     Path loadPath = new Path();
     List<Path> allLoadedPathes = new List<Path>();
     using (StreamReader reader = new StreamReader(@"../../LoadPaths.txt"))
     {
         for (var line = reader.ReadLine(); line != null; line = reader.ReadLine())
         {
             Point3D point = new Point3D();
             string[] points = line.Split(',');
             point.X = int.Parse(points[0]);
             point.Y = int.Parse(points[1]);
             point.Z = int.Parse(points[2]);
             loadPath.AddPoint(point);
         }
         allLoadedPathes.Add(loadPath);
         loadPath = new Path();
     }
     return allLoadedPathes;
 }
Пример #5
0
        static void Main(string[] args)
        {
            //testing distance between two points
            Point3D p1 = new Point3D(10, 20, 30);
            Point3D p2 = new Point3D(); // (0,0,0) inline initialization

            double distance = PointsDistance.CalculateDistance(p1, p2);
            Console.WriteLine("Distance: {0:F2}",distance);
            Console.WriteLine(separator);

            //testing adding points to path
            Path path = new Path();
            path.AddPoint(p1);
            path.AddPoint(p2);
            path.AddPoint(Point3D.StartOfCoordSystem);
            path.AddPoint(new Point3D(5, 6, 7));
            foreach (Point3D point in path.Sequence)
            {
                Console.WriteLine(point);
            }
            Console.WriteLine(separator);

            //saving path test
            PathStorage.SavePath(path);

            Console.WriteLine(separator);

            //loading path from file test
            List<Path> list = PathStorage.LoadPaths("paths.txt");
            for (int i = 0; i < list.Count; i++)
            {
                foreach (Point3D point in list[i].Sequence)
                {
                    Console.WriteLine(point);
                }
            }
        }
Пример #6
0
        static void Main()
        {
            Point3D p1 = new Point3D(1, 2, 3);
            Point3D p2 = new Point3D(4, 5, 6);

            Console.WriteLine("1: " + p1);
            Console.WriteLine("2: " + p2);
            Console.WriteLine("Distance: " + Distance.CalcDistance(p1, p2));

            Console.WriteLine("Zero Point:");
            Console.WriteLine(Point3D.zero);

            Path pathSequence = new Path();
            pathSequence.AddPoint(p2);
            pathSequence.AddPoint(p1);
            pathSequence.AddPoint(p2);

            PathStorage.SavePath(pathSequence);
            List<Path> pathList = PathStorage.LoadPath();
            foreach (var path in pathList)
            {
                Console.WriteLine("-----Path Start-------");
                foreach (var p in path.Sequence)
                {
                    Console.WriteLine(p);
                }
                Console.WriteLine("-----Path End-------");

            }

            Console.WriteLine("Path Sequence: ");
            foreach (var item in pathSequence.sequence)
            {
                Console.WriteLine(item);
            }
        }
Пример #7
0
 public void AddPoint(Point3D point)
 {
     Points.Add(point);
 }
Пример #8
0
        public static double Calculate(Point3D p1, Point3D p2)
        {
            double result = Math.Sqrt(Math.Pow((p1.X - p2.X), 2) + Math.Pow((p1.Y - p2.Y), 2) + Math.Pow((p1.Z - p2.Z), 2));

            return result;
        }
Пример #9
0
 public void AddPoint(Point3D point3D)
 {
     this.points.Add(point3D);
 }
Пример #10
0
            public static double Calculate(Point3D.Point a, Point3D.Point b)
            {
                int deltaX = b.X - a.X;
                int deltaY = b.Y - a.Y;
                int deltaZ = b.Z - a.Z;

                return Math.Sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ);
            }
Пример #11
0
 static Point3D()
 {
     pointZero = new Point3D(0, 0, 0);
 }
Пример #12
0
 public void AddPoint(Point3D point)
 {
     sequence.Add(point);
 }
Пример #13
0
 public static double CalculateDistance(Point3D firstPoint, Point3D secondPoint)
 {
     double distance = 0d;
     distance = Math.Sqrt(Math.Pow(firstPoint.X - secondPoint.X, 2) + Math.Pow(firstPoint.Y - secondPoint.Y, 2) + Math.Pow(firstPoint.Z - secondPoint.Z, 2));
     return distance;
 }