public static double Calculate3DDistance(Point3D point1, Point3D point2)
        {
            double distance = 0;
            distance = Math.Sqrt(Math.Pow((point1.X - point2.X), 2) + Math.Pow((point1.Y - point2.Y), 2) + Math.Pow((point1.Z - point2.Z), 2));

            return distance;
        }
        public static List<Path> LoadPath()
        {
            Path loadPath = new Path();
            List<Path> loadedPaths = new List<Path>();
            using (StreamReader readPath = new StreamReader(@"../../SavedPaths.txt"))
            {
                string readLine = readPath.ReadLine();
                while (readLine != null)
                {
                    if (readLine != "***")
                    {
                        Point3D point = new Point3D();
                        char[] splitChars = new char[]{ ',', '(', ')'};
                        string[] points = readLine.Split(splitChars,StringSplitOptions.RemoveEmptyEntries);
                        point.X = int.Parse(points[0]);
                        point.Y = int.Parse(points[1]);
                        point.Z = int.Parse(points[2]);
                        loadPath.AddPoint(point);
                    }
                    else
                    {
                        loadedPaths.Add(loadPath);
                        loadPath = new Path();
                    }

                    readLine = readPath.ReadLine();
                }
            }
            return loadedPaths;
        }
        static void Main()
        {
            //Create 3 points
            Point3D pointOne = new Point3D(2, 3, 4);
            Point3D pointTwo = new Point3D(0, -3, 10);
            Point3D pointThree = new Point3D(7, -9, -12);

            //Print the points on the console
            Console.WriteLine("Point 1: {0}", pointOne);
            Console.WriteLine("Point 2: {0}", pointTwo);
            Console.WriteLine("Point 3: {0}", pointThree);

            //Calculate the distance between PointOne and PointTwo
            double distance1To2 = Distance3D.Calculate3DDistance(pointOne, pointTwo);
            Console.WriteLine("The distance between point 1 {0} and point 2 {1} is {2:F2}", pointOne, pointTwo, distance1To2);

            //Create 2 paths
            Path pathOne = new Path();
            pathOne.AddPoint(pointOne);
            pathOne.AddPoint(pointThree);

            Path pathTwo = new Path();
            pathTwo.AddPoint(Point3D.CoordinateSystemStart);
            pathTwo.AddPoint(pointTwo);
            pathTwo.AddPoint(pointThree);

            //Save the two paths in a txt file
            PathStorage.SavePath(pathOne);
            PathStorage.SavePath(pathTwo);

            //Load paths
            List<Path> loadedPaths = PathStorage.LoadPath();
            Console.WriteLine("Paths loaded!");
        }
Exemplo n.º 4
0
 //Method to add a point
 public void AddPoint(Point3D point)
 {
     pathPoints.Add(point);
 }