Exemplo n.º 1
0
        static void Main(string[] args)
        {
            // creating a new point and printing its coordinates
            Point3D pointOne = new Point3D(3, 4, 5);
            Point3D pointTwo = new Point3D(4, 7, 9);
            Console.WriteLine(pointOne.ToString());
            Console.WriteLine(pointTwo.ToString());

            // printing the static zero point's coordinates
            Console.WriteLine(Point3D.ZeroPoint.ToString());

            // Euclidian distance
            Console.WriteLine(DistanceBetweenPoints.GetDistanceBetweenPoints(pointOne, pointTwo));

            // creating new sequence of points; adding the created points to the sequence; saving the sequence to a file;
            // clearing  the sequence; reading the file and filling the initiated sequence again, after which printing their coordinates
            Path points = new Path();
            points.AddPointToSequnce(pointOne);
            points.AddPointToSequnce(pointTwo);
            points.AddPointToSequnce(Point3D.ZeroPoint);
            PathStorage.SavePathToFile(points);
            points.ClearSequence();

            points = PathStorage.LoadLastPathFromFile();
            foreach (var point in points.SequenceOfPoints)
            {
                Console.WriteLine(point.ToString());
            }
        }
        public static Path LoadLastPathFromFile()
        {
            Path newSequence = new Path();
            using (StreamReader reader = new StreamReader(@"../../SavedPath.txt"))
            {
                string line = reader.ReadLine();
                while (line != null)
                {
                    if (!string.IsNullOrWhiteSpace(line))
                    {
                        if ((char.IsDigit(line[0])))
                        {
                            string[] components = line.Split();
                            Point3D newPoint = new Point3D(int.Parse(components[1]), int.Parse(components[2]), int.Parse(components[3]));
                            newSequence.AddPointToSequnce(newPoint);
                        }
                    }
                    line = reader.ReadLine();
                }
            }

            if (newSequence.SequenceOfPoints.Count == 0)
            {
                throw new FileLoadException("The file you are trying to load is empty!");
            }

            return newSequence;
        }
        public static double GetDistanceBetweenPoints(Point3D first, Point3D second)
        {
            double distance = 0;
            distance = Math.Sqrt(((first.coordX - second.coordX) * (first.coordX - second.coordX)) +
                                    ((first.coordY - second.coordY) * (first.coordY - second.coordY)) +
                                    ((first.coordZ - second.coordZ) * (first.coordZ - second.coordZ)));

            return distance;
        }
Exemplo n.º 4
0
 public void AddPointToSequnce(Point3D point)
 {
     this.SequenceOfPoints.Add(point);
 }