Beispiel #1
0
 public static void SavePath(Path3D path, string filePath)
 {
     using (StreamWriter writer = new StreamWriter(filePath))
     {
         writer.Write(path.ToString());
     }
 }
Beispiel #2
0
        public static void Main()
        {
            // The first three problems are in this project

            Point3D point = new Point3D(5.4m, 6.6m, 3.1m);

            Console.WriteLine(point);

            Point3D anotherPoint = new Point3D(1m, 5.78m, -2.75m);

            Console.WriteLine(anotherPoint);

            Console.WriteLine("{0:F3}", DistanceCalculation.CalculateDistance(point, anotherPoint));

            Point3D basePoint = Point3D.StartingPoint;

            Console.WriteLine(basePoint);

            Path3D listOfPoints = new Path3D();

            listOfPoints.AddPoint(point);
            listOfPoints.AddPoint(basePoint);
            listOfPoints.AddPoint(anotherPoint);

            Storage.SavePath(listOfPoints);
        }
Beispiel #3
0
        static void Main()
        {
            Point3D newPoint = new Point3D(0, 1, 2);
            Console.WriteLine("Point 1: {0}", newPoint.ToString());
            Console.WriteLine(new string('=', 30));

            Point3D center = Point3D.GetCoordinateCenter;
            Console.WriteLine("Start: {0}", center.ToString());
            Console.WriteLine(new string('=', 30));

            Console.WriteLine("Distance between points = {0:F2}", Distance.Calculate(newPoint, center));
            Console.WriteLine(new string('=', 30));

            string filePath = "storage.txt";
            List<Point3D> points = new List<Point3D>();
            points.Add(newPoint);
            points.Add(center);
            Path3D path = new Path3D(points);
            Storage.Save(path, filePath);

            Path3D readPath = Storage.Load("storage.txt");
            int counter = 1;
            foreach (var point in readPath.Path)
            {
                Console.WriteLine("Point {3}: X = {0}, Y = {1}, Z = {2}", point.X, point.Y, point.Z, counter);
                counter++;
            }
            Console.WriteLine();
        }
Beispiel #4
0
        public static void Main(string[] args)
        {
            Point3D point         = new Point3D(2.5, 1, 3);
            Point3D startingPoint = Point3D.GetStartingPoint;

            //Homework Problem 1
            //Print point
            Console.WriteLine(point.ToString());

            //Homework Problem 1
            //Print starting point
            Console.WriteLine(startingPoint.ToString());

            //Homework Problem 2
            //Calculate and print dostance between point and starting point
            Console.WriteLine(DistanceCalculator.CalculateDistance(point, startingPoint));

            //Homework Problem 3
            //Create path and add two points
            Path3D path = new Path3D();

            path.AddPoint(point);
            path.AddPoint(startingPoint);

            //Save file
            Storage.SavePath(path, filePath);

            //Load file
            Console.WriteLine();
            Storage.LoadPath(filePath);
        }
Beispiel #5
0
 public static void SavePath(string file, Path3D path, bool append = true)
 {
     using (StreamWriter writer = new StreamWriter(file, append))
     {
         writer.WriteLine(path);
     }
 }
Beispiel #6
0
        public static void Main()
        {
            // Make two points
            var pointA = new Point(5, 6, 2);
            var pointB = new Point(-7, 11, -13);

            // Print the points
            Console.WriteLine("Point a: {0}", pointA);
            Console.WriteLine("Point b: {0}", pointB);
            Console.WriteLine();

            // Calculate the distance
            double distance = DistanceCalculator.CalculateDistance(pointA, pointB);
            Console.WriteLine("Distance [a -> b] = {0:0.00}", distance);

            // Add a points to the List<>
            var path = new Path3D();

            //path.AddPoint(pointA);
            path.AddPoint(pointB);

            // Save the points from the List<> to .txt
            Storage.SavePoint(path);
            Console.WriteLine();

            // Load the points from the file
            Console.WriteLine("Loaded points:");
            Storage.LoadPoint();
            Console.WriteLine();
        }
Beispiel #7
0
 public static void SavePath(string file, Path3D path, bool append = true)
 {
     using (StreamWriter writer = new StreamWriter(file, append))
     {
         writer.WriteLine(path);
     }
 }
Beispiel #8
0
        static void Main()
        {
            Point3D point1 = new Point3D(-7, -4, 3);
            Point3D point2 = new Point3D(17, 6, 2.5);

            // Display Points
            Console.WriteLine("Starting point: " + Point3D.StartingPoint);
            Console.WriteLine("Point3D 1: " + point1);
            Console.WriteLine("Point3D 1: " + point2);

            // Display Distance Between Points
            double distance = DistanceCalculator.CalculateDistance(point1, point2);

            Console.WriteLine();
            Console.WriteLine("Distance: " + distance);
            Console.WriteLine();

            // Display Path
            Path3D path = new Path3D(point1, point2);
            path.AddPoint(new Point3D(4, 6.4, 11.1));

            // if 3th value is true, the path will be appended to old file data, else the file will be overwritten
            Storage.SavePath("paths.txt", path, false);
            Console.WriteLine("Path: " + path);

            string storageData = Storage.LoadPath("paths.txt");
            Console.WriteLine("\nPath from Storage:\n" + storageData);
        }
Beispiel #9
0
        public static void LoadPoint()
        {
            var loadPath = new StreamReader(SavedPaths);
            var loadedPath = new Path3D();

            using (loadPath)
            {
                string line = loadPath.ReadLine();

                while (line != null)
                {
                    var currentLine = line.Split(new char[] { ' ', ',', '=' },
                                                 StringSplitOptions.RemoveEmptyEntries);

                    var currnetPath = new Point(double.Parse(currentLine[1]),
                                                double.Parse(currentLine[3]),
                                                double.Parse(currentLine[5]));

                    loadedPath.AddPoint(currnetPath);
                    line = loadPath.ReadLine();
                }
            }

            foreach (var path in loadedPath.PathList)
            {
                Console.WriteLine(path);
            }
        }
Beispiel #10
0
        public static void Main()
        {
            Point3D firstPoint = new Point3D();
            Point3D secondPoint = new Point3D(2.5, 55556, 8);
            firstPoint.X = 5;
            Console.WriteLine(firstPoint.ToString());

            Point3D beginning = Point3D.StartignPoint;
            Console.WriteLine("The beginning of the coordinate system is {0}", beginning.ToString());

            double distance = DistanceCalculator.BetweenTwoPointsIn3D(beginning, firstPoint);
            Console.WriteLine("The distance between them is: " + distance);
            Console.WriteLine();

            Path3D path1 = new Path3D(firstPoint, secondPoint, beginning, firstPoint);

            Console.Write("Enter path name: ");
            string pathName = Console.ReadLine();

            while (!Storage.WritePath(path1, pathName))
            {
                Console.Write("Path with that name already exists. Enter diffrent name:");
                pathName = Console.ReadLine();
            }

            Console.WriteLine("File successfully created.\n");

            Path3D path2 = new Path3D(beginning, firstPoint, secondPoint);
            Storage.WritePath(path2, "Path2");

            Console.WriteLine(Storage.ReadPath("Path2"));
            Console.WriteLine();
            Console.WriteLine(Storage.ReadPath("Path"));
        }
Beispiel #11
0
 public static void SavePointsToFile(string fileName, Path3D points)
 {
     using (StreamWriter writer = new StreamWriter(fileName, false))
     {
         writer.WriteLine(points);
     }
 }
Beispiel #12
0
        static void Main()
        {
            Point3D point1 = new Point3D(-7, -4, 3);
            Point3D point2 = new Point3D(17, 6, 2.5);

            // Display Points
            Console.WriteLine("Starting point: " + Point3D.StartingPoint);
            Console.WriteLine("Point3D 1: " + point1);
            Console.WriteLine("Point3D 1: " + point2);


            // Display Distance Between Points
            double distance = DistanceCalculator.CalculateDistance(point1, point2);

            Console.WriteLine();
            Console.WriteLine("Distance: " + distance);
            Console.WriteLine();


            // Display Path
            Path3D path = new Path3D(point1, point2);

            path.AddPoint(new Point3D(4, 6.4, 11.1));

            // if 3th value is true, the path will be appended to old file data, else the file will be overwritten
            Storage.SavePath("paths.txt", path, false);
            Console.WriteLine("Path: " + path);

            string storageData = Storage.LoadPath("paths.txt");

            Console.WriteLine("\nPath from Storage:\n" + storageData);
        }
Beispiel #13
0
 public static Path3D LoadPathFromFile(string fileName)
 {
     try
     {
         Path3D path = new Path3D();
         using (StreamReader sr = new StreamReader(fileName))
         {
             string          input   = sr.ReadToEnd();
             string          pattern = @"Point\(([\d.]+),([\d.]+),([\d.]+)\)";
             Regex           rgx     = new Regex(pattern);
             MatchCollection matches = rgx.Matches(input);
             foreach (Match match in matches)
             {
                 double  x     = double.Parse(match.Groups[1].Value);
                 double  y     = double.Parse(match.Groups[2].Value);
                 double  z     = double.Parse(match.Groups[3].Value);
                 Point3D point = new Point3D(x, y, z);
                 path.AddPoint(point);
             }
         }
         return(path);
     }
     catch (IOException ex)
     {
         Console.WriteLine(ex.Message);
         throw ex.InnerException;
     }
 }
Beispiel #14
0
        public static Path3D LoadPointsFromFile(string fileName)
        {
            Path3D points = new Path3D();

            using (StreamReader reader = new StreamReader(fileName))
            {
                string text = reader.ReadToEnd();

                string pattern = "(\\-*\\d*\\.*\\d), (\\-*\\d*\\.*\\d), (\\-*\\d*\\.*\\d)";

                var reg     = new Regex(pattern);
                var matches = reg.Matches(text);

                foreach (Match match in matches)
                {
                    double x = double.Parse(match.Groups[1].Value);
                    double y = double.Parse(match.Groups[2].Value);
                    double z = double.Parse(match.Groups[3].Value);

                    Point3D currentPoint = new Point3D(x, y, z);
                    points.AddPoints(currentPoint);
                }
            }

            return(points);
        }
Beispiel #15
0
 public static void SavePath(Path3D path, string filePath)
 {
     using (StreamWriter writer = new StreamWriter(filePath))
     {
         writer.Write(path.ToString());
     }
 }
Beispiel #16
0
        static void Main(string[] args)
        {
            //test Problem 1.Point3D
            Point3D myPoint = new Point3D(2, 4, 7);
            Point3D center  = Point3D.StartingPoint;

            Console.WriteLine(myPoint);
            Console.WriteLine(center);

            //test Problem 2.Distance Calculator
            Point3D firstPoint  = new Point3D(1, 2, 4);
            Point3D secondPoint = new Point3D(1.4, 4.9, 2);
            double  dist        = DistanceCalculator.CalcDistance(firstPoint, secondPoint);

            Console.WriteLine("The distance between the two points is {0:F}", dist);

            //test Problem 3.Paths
            Path3D myPath = new Path3D(myPoint, firstPoint, secondPoint, center);

            Console.WriteLine(myPath);
            Console.WriteLine("Save path: {0}", myPath);
            Storage.SavePathInFile("path.txt", myPath);
            Path3D loadPath = Storage.LoadPathFromFile("path.txt"); //the file is in: "2.Static-Members-and-Namespaces-Homework\Point3D\bin\Debug"

            Console.WriteLine("Load path: {0}", loadPath);
        }
Beispiel #17
0
        static void Main(string[] args)
        {
            Point3D pointA = new Point3D(0, 0, 0);
            Point3D pointB = new Point3D(1, 1, 1);

            Console.WriteLine(pointA);
            Console.WriteLine(pointB);
            Point3D a = Point3D.StartPoint;
            Console.WriteLine(a);

            double result = DistanceCalculator.CalcDistance(pointA, pointB);
            Console.WriteLine(result);

            Path3D path = new Path3D(new List<Point3D>()
            {
                new Point3D(0,0,0),
                new Point3D(1,2,3),
                new Point3D(2,2,2),
                new Point3D(1,4,5),
                new Point3D(4,7,8)
               });
            Storage.SaveFile(path.ReturnPoints);
            var load = Storage.LoadFile("Points.txt");
            Path3D secPath = new Path3D(load);
        }
Beispiel #18
0
 public static void Save(Path3D path)
 {
     using (StreamWriter write = new StreamWriter(@"C:\Users\garrett\Desktop\write.txt"))
     {
         foreach (var point3D in path.Points)
         {
             write.WriteLine($"{point3D.GetType()}: {point3D.X} {point3D.Y} {point3D.Z}");
         }
     }
 }
Beispiel #19
0
 public static void Main(string[] args)
 {
     Point3D a = new Point3D(2, 2, 2);
     Point3D b = new Point3D(3, 3, 3);
     var list = new List<Point3D>();
     list.Add(a);
     list.Add(b);
     Path3D path = new Path3D(list);
     Storage.Save(path);
 }
Beispiel #20
0
 public static void Save(Path3D path, string filePath)
 {
     using (StreamWriter writer = new StreamWriter(filePath, false))
     {
         foreach (var point in path.Path)
         {
             writer.WriteLine(string.Format("{0} {1} {2}", point.X, point.Y, point.Z));
         }
     }
 }
Beispiel #21
0
        public static void SavePath(Path3D path)
        {
            string file = "../../save.bin";

            using (Stream stream = File.Open(file, FileMode.Create))
            {
                var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

                bformatter.Serialize(stream, path.Path);
            }
        }
Beispiel #22
0
        public static void SavePath(Path3D path)
        {
            string file = "../../save.bin";

            using (Stream stream = File.Open(file, FileMode.Create))
            {
                var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

                bformatter.Serialize(stream, path.Path);
            }
        }
Beispiel #23
0
        public static void SavePath(string fileName, Path3D currentPath)
        {
            StreamWriter writer = new StreamWriter(fileName);

            using (writer)
            {
                foreach (Point3D point in currentPath.PointList)
                {
                    writer.WriteLine(point.X + " " + point.Y + " " + point.Z);
                }
            }
        }
Beispiel #24
0
        public static void LoadPathFromFile(string file, ref Path3D path)
        {
            string pathData = System.IO.File.ReadAllText(file);

            // Console.WriteLine(   Regex.Match(pathData, @"\(([^)]*)\)").Groups[1].Value);

            foreach (Match m in Regex.Matches(pathData, @"\(([^)]*)\)"))
            {
                // Console.WriteLine(m.Value.Replace("(","").Replace(")","").Split(',')[0]);   )
                path.addPointToPath(new Point3D(m.Value.Replace("(", "").Replace(")", "").Split(',')));
            }
        }
Beispiel #25
0
        public static void LoadPathFromFile(string file, ref Path3D path)
        {
            string pathData = System.IO.File.ReadAllText(file);
            // Console.WriteLine(   Regex.Match(pathData, @"\(([^)]*)\)").Groups[1].Value);

            foreach (Match m in Regex.Matches(pathData, @"\(([^)]*)\)"))
            {

                // Console.WriteLine(m.Value.Replace("(","").Replace(")","").Split(',')[0]);   )
                path.addPointToPath(new Point3D(m.Value.Replace("(", "").Replace(")", "").Split(',')));
            }
        }
Beispiel #26
0
        static void Main(string[] args)
        {
            Point3D one = new Point3D(1, 1, 1);
            Point3D two = new Point3D(2, 4, 8);
            Path3D firstPath = new Path3D();
            firstPath.AddPoint3D(one, two);
            Path3D secondPath = new Path3D(one, two);

            Console.WriteLine("{0:F4}", DistanceCalculator.CalculateDistanceBetweenPoints(one, two));

            Console.WriteLine(firstPath);
            Console.WriteLine(secondPath);

            Point3D temp = Point3D.StartingPoint();
        }
Beispiel #27
0
        static void Main(string[] args)
        {
            Point3D firstPoint  = new Point3D(3, -5, 3.5);
            Point3D secondPoint = new Point3D(-5, 9, 8.9);

            Console.WriteLine("First point: {0}", firstPoint);
            Console.WriteLine("Second point: {0}", secondPoint);

            Console.WriteLine("Distance between first and second point is " + DistanceCalculator.CalculateDistance(firstPoint, secondPoint));

            Path3D path = new Path3D(firstPoint, secondPoint);

            Storage.SavePointsToFile("output.txt", path);

            Path3D loadedFromFile = Storage.LoadPointsFromFile("output.txt");

            Console.WriteLine("Points loaded from file are : {0}", loadedFromFile);
        }
Beispiel #28
0
        public static Path3D LoadPath()
        {
            string file = "../../save.bin";
            using (Stream stream = File.Open(file, FileMode.Open))
            {
                var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

                List<Point3D> loadedPath = (List<Point3D>)bformatter.Deserialize(stream);

                Path3D path = new Path3D();
                foreach (var loadP in loadedPath)
                {
                    path.AddPoint3DToPath(loadP);
                }

                return path;
            }
        }
Beispiel #29
0
        public static Path3D LoadPath()
        {
            string file = "../../save.bin";

            using (Stream stream = File.Open(file, FileMode.Open))
            {
                var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

                List <Point3D> loadedPath = (List <Point3D>)bformatter.Deserialize(stream);

                Path3D path = new Path3D();
                foreach (var loadP in loadedPath)
                {
                    path.AddPoint3DToPath(loadP);
                }

                return(path);
            }
        }
Beispiel #30
0
        public static void SavePoint(Path3D path)
        {
            try
            {
                var savePath = new StreamWriter(SavedPaths);

                using (savePath)
                {
                    foreach (var point in path.PathList)
                    {
                        savePath.WriteLine(point);
                    }
                }
            }
            catch (IOException io)
            {
                Console.WriteLine(io.Message);
            }
        }
Beispiel #31
0
        public static void Main(string[] args)
        {
            Point3D p1 = new Point3D(1.1, 2.2, 3.3);
            Point3D p2 = new Point3D(2.1, 3.2, 4.3);
            Console.WriteLine(p1);
            Console.WriteLine(p2);
            Console.WriteLine("Zero point: " + Point3D.StartingPoint);

               double distance = DistanceCalculator.CalculateDistanceBetween3DPoints(p1, p2);
            Console.WriteLine("Distance is: " + distance);

            Path3D myPath = new Path3D();
            myPath.AddPoint3DToPath(p1);
            myPath.AddPoint3DToPath(p2);
            Console.WriteLine(myPath);

            Storage.SavePath(myPath);
            Path3D loadedPath = Storage.LoadPath();
            Console.WriteLine(loadedPath);
        }
Beispiel #32
0
        public static Path3D LoadPath(string fileName)
        {
            Path3D data = new Path3D();
            StreamReader reader = new StreamReader(fileName);

            using (reader)
            {
                string currentLine = reader.ReadLine();

                while (currentLine != null)
                {
                    string[] currentPoint = currentLine.Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
                    Point3D point = new Point3D(int.Parse(currentPoint[0]), int.Parse(currentPoint[1]), int.Parse(currentPoint[2]));
                    data.AddPoint3D(point);
                    currentLine = reader.ReadLine();
                }
            }

            return data;
        }
Beispiel #33
0
        public static void Main()
        {
            Point3D point = new Point3D(3, 3, 3);
            Console.WriteLine(point);
            Console.WriteLine(Point3D.StartingPoint);
            var dist = DistanceCalculator.CalcDistance(point, Point3D.StartingPoint);
            Console.WriteLine("The distance between point One {0} and point two {1} is {2:F2}",point,Point3D.StartingPoint, dist);

            // testing Path3D
            Path3D pathToHome = new Path3D();
            pathToHome.AddPoint(new Point3D(1, 2, 3));
            pathToHome.AddPoint(new Point3D(2, 21, 3));
            pathToHome.AddPoint(new Point3D(11, 0, 3));
            pathToHome.AddPoint(new Point3D(1, 2, 3));
            pathToHome.AddPoint(new Point3D(4, 5, 6));
            pathToHome.AddPoint(new Point3D(7, 8, 8));
            Console.WriteLine(pathToHome);

            //Testing Storage methods that save and load files with given 3dpa
            Storage.LoadPath(@"D:\Mirchev\SoftUni\OOP\StaticMembersAndNamespaces\Point3D\navigation.txt");
            Storage.SavePath(@"D:\Mirchev\SoftUni\OOP\StaticMembersAndNamespaces\Point3D\naviToHome.txt", pathToHome);
        }
Beispiel #34
0
        public static void Main()
        {
            Point3D firstPoint  = new Point3D();
            Point3D secondPoint = new Point3D(2.5, 55556, 8);

            firstPoint.X = 5;
            Console.WriteLine(firstPoint.ToString());

            Point3D beginning = Point3D.StartignPoint;

            Console.WriteLine("The beginning of the coordinate system is {0}", beginning.ToString());

            double distance = DistanceCalculator.BetweenTwoPointsIn3D(beginning, firstPoint);

            Console.WriteLine("The distance between them is: " + distance);
            Console.WriteLine();

            Path3D path1 = new Path3D(firstPoint, secondPoint, beginning, firstPoint);

            Console.Write("Enter path name: ");
            string pathName = Console.ReadLine();

            while (!Storage.WritePath(path1, pathName))
            {
                Console.Write("Path with that name already exists. Enter diffrent name:");
                pathName = Console.ReadLine();
            }

            Console.WriteLine("File successfully created.\n");

            Path3D path2 = new Path3D(beginning, firstPoint, secondPoint);

            Storage.WritePath(path2, "Path2");

            Console.WriteLine(Storage.ReadPath("Path2"));
            Console.WriteLine();
            Console.WriteLine(Storage.ReadPath("Path"));
        }
Beispiel #35
0
 public static void SavePathInFile(string fileName, Path3D path)
 {
     try
     {
         using (StreamWriter writer = new StreamWriter(fileName))
         {
             writer.WriteLine(path);
         }
     }
     catch (DirectoryNotFoundException ex)
     {
         Console.WriteLine("File path contains an invalid directory");
     }
     catch (UnauthorizedAccessException)
     {
         Console.WriteLine("Unauthorized access to specified file path");
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         throw ex.InnerException;
     }
 }
Beispiel #36
0
        public static void Main(string[] args)
        {
            Point3D p1 = new Point3D(1.1, 2.2, 3.3);
            Point3D p2 = new Point3D(2.1, 3.2, 4.3);

            Console.WriteLine(p1);
            Console.WriteLine(p2);
            Console.WriteLine("Zero point: " + Point3D.StartingPoint);

            double distance = DistanceCalculator.CalculateDistanceBetween3DPoints(p1, p2);

            Console.WriteLine("Distance is: " + distance);

            Path3D myPath = new Path3D();

            myPath.AddPoint3DToPath(p1);
            myPath.AddPoint3DToPath(p2);
            Console.WriteLine(myPath);

            Storage.SavePath(myPath);
            Path3D loadedPath = Storage.LoadPath();

            Console.WriteLine(loadedPath);
        }
Beispiel #37
0
 public static Path3D Load(string filePath)
 {
     List<Point3D> points = new List<Point3D>();
     using (StreamReader reader = new StreamReader(filePath))
     {
         string line;
         while (!string.IsNullOrEmpty(line = reader.ReadLine()))
         {
             string[] coordinates = line.Split(' ');
             if (coordinates.Length != 3)
             {
                 reader.Close();
                 throw new InvalidDataException("Input file contains wrong point coordinates data.");
             }
             double x = double.Parse(coordinates[0]);
             double y = double.Parse(coordinates[1]);
             double z = double.Parse(coordinates[2]);
             Point3D point = new Point3D(x, y, z);
             points.Add(point);
         }
     }
     Path3D path = new Path3D(points);
     return path;
 }
Beispiel #38
0
 public static void SavePathToFile(string file, Path3D path)
 {
     System.IO.File.WriteAllText(file, path.ToString());
 }
Beispiel #39
0
 public static void SavePathToFile(string file, Path3D path)
 {
     System.IO.File.WriteAllText(file, path.ToString());
 }