コード例 #1
0
        public static Path Load()
        {
            Path loaded = new Path();
            StreamReader reader = new StreamReader("file.txt");

            using (reader)
            {
                string line = reader.ReadLine();
                while (line != null)
                {
                    string[] currentLine;
                    Point3d currentPoint = new Point3d();
                    currentLine = ExtractPaths(line);

                    if (currentLine.Length == 3)
                    {
                        currentPoint.X = int.Parse(currentLine[0]);
                        currentPoint.Y = int.Parse(currentLine[1]);
                        currentPoint.Z = int.Parse(currentLine[2]);
                    }
                    else
                    {
                        throw new IndexOutOfRangeException("You could use exactly three points");
                    }

                    loaded.Add(currentPoint);
                    line = reader.ReadLine();
                }
            }

            return loaded;
        }
コード例 #2
0
        public static double Distance(Point3d p1, Point3d p2)
        {
            double x = Math.Pow(p1.X - p2.X, 2);
            double y = Math.Pow(p1.Y - p2.Y, 2);
            double z = Math.Pow(p1.Z - p2.Z, 2);
            double distance = Math.Sqrt(x + y + z);

            return distance;
        }
コード例 #3
0
        private static void Main()
        {
            Point3d firstPoint = new Point3d(1, 2, 3);
            Point3d secondPoint = new Point3d(4, 5, 6);

            Console.WriteLine("First point " + firstPoint);
            Console.WriteLine("Second point " + secondPoint);
            Console.WriteLine("Start point " + Point3d.StartPoint);
            Console.WriteLine("Distance between first and second point " + Calculate3d.Distance(firstPoint, secondPoint));

            Path paths = new Path();
            paths.Add(firstPoint);
            paths.Add(secondPoint);

            Console.WriteLine("All points: ");
            Console.Write(paths);

            PathStorage.Save(paths);

            Console.WriteLine("Loaded: ");
            Path loadedPaths = PathStorage.Load();
            Console.Write(loadedPaths);
        }
コード例 #4
0
ファイル: Path.cs プロジェクト: deyantodorov/TelerikAcademy
 public void Delete(Point3d point)
 {
     this.Points.Add(point);
 }
コード例 #5
0
ファイル: Path.cs プロジェクト: deyantodorov/TelerikAcademy
 public void Add(Point3d point)
 {
     this.Points.Add(point);
 }