static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            Point3D start = Point3D.StartingPoint;
            Console.WriteLine(start);
            Point3D p = new Point3D(2.3, 4.8, 16.9);
            Console.WriteLine(p);
            Point3D q = new Point3D(2.8, 16, -5);
            Console.WriteLine(p);

            double distance = DistanceCalculator.CalcDistance(q, p);
            Console.WriteLine("The distance between the points is: " + distance);

            Path3D myPath = new Path3D(p, q, start);
            Console.WriteLine("My path is: ");
            Console.WriteLine(myPath);
            Console.WriteLine("My path's total lenght is: " + myPath.TotalDistance);

            Storage.WritePathToTxt(myPath);

            Path3D readedPath = Storage.ReadPathFromTxt("../../txtFiles/input.txt");
            Console.WriteLine("This path war read from the text file: ");
            Console.WriteLine(readedPath);
            Console.WriteLine("Readed path's total lenght is: " + readedPath.TotalDistance);
        }
Exemple #2
0
        static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            Point3D start = Point3D.StartingPoint;

            Console.WriteLine(start);
            Point3D p = new Point3D(2.3, 4.8, 16.9);

            Console.WriteLine(p);
            Point3D q = new Point3D(2.8, 16, -5);

            Console.WriteLine(p);

            double distance = DistanceCalculator.CalcDistance(q, p);

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

            Path3D myPath = new Path3D(p, q, start);

            Console.WriteLine("My path is: ");
            Console.WriteLine(myPath);
            Console.WriteLine("My path's total lenght is: " + myPath.TotalDistance);

            Storage.WritePathToTxt(myPath);

            Path3D readedPath = Storage.ReadPathFromTxt("../../txtFiles/input.txt");

            Console.WriteLine("This path war read from the text file: ");
            Console.WriteLine(readedPath);
            Console.WriteLine("Readed path's total lenght is: " + readedPath.TotalDistance);
        }
        public static void WritePathToTxt(Path3D path)
        {
            StreamWriter writer = new StreamWriter(Output);

            using (writer)
            {
                foreach (var point in path.Points)
                {
                    writer.WriteLine(point);
                }
            }
        }
        public static void WritePathToTxt(Path3D path)
        {
            StreamWriter writer = new StreamWriter(Output);

            using (writer)
            {
                foreach (var point in path.Points)
                {
                    writer.WriteLine(point);
                }
            }
        }
Exemple #5
0
        public static Path3D readPathFromFile(string filename)
        {
            string pathFromFile = File.ReadAllText(filename);
            Regex  pattern      = new Regex("x = (.*?); y = (.*?); z = (.*?)[)]");
            var    matches      = pattern.Matches(pathFromFile);
            Path3D path         = new Path3D();

            for (int i = 0; i < matches.Count; i++)
            {
                double  x     = Double.Parse(matches[i].Groups[1].Value);
                double  y     = Double.Parse(matches[i].Groups[2].Value);
                double  z     = Double.Parse(matches[i].Groups[3].Value);
                Point3D point = new Point3D(x, y, z);
                path.points.Add(point);
            }
            return(path);
        }
 public static Path3D ReadPathFromTxt(string pathToFile)
 {
     Path3D result = new Path3D();
     StreamReader reader = new StreamReader(pathToFile);            
     using (reader)
     {
         string line = reader.ReadLine();
         while (line != null)
         {
             string[] coords = line.Split (new char[] { 'X', 'Y', 'Z', ' ', ':' },
                 StringSplitOptions.RemoveEmptyEntries);
             result.Points.Add(new Point3D 
                 (Double.Parse(coords[0]), Double.Parse(coords[1]), Double.Parse(coords[2])));
             line = reader.ReadLine();
         }
     }
     return result;
 }
        public static Path3D ReadPathFromTxt(string pathToFile)
        {
            Path3D       result = new Path3D();
            StreamReader reader = new StreamReader(pathToFile);

            using (reader)
            {
                string line = reader.ReadLine();
                while (line != null)
                {
                    string[] coords = line.Split(new char[] { 'X', 'Y', 'Z', ' ', ':' },
                                                 StringSplitOptions.RemoveEmptyEntries);
                    result.Points.Add(new Point3D
                                          (Double.Parse(coords[0]), Double.Parse(coords[1]), Double.Parse(coords[2])));
                    line = reader.ReadLine();
                }
            }
            return(result);
        }
Exemple #8
0
        static void Main(string[] args)
        {
            Point3D firstPoint = new Point3D(3, 5, -4);

            Console.WriteLine(firstPoint.ToString());

            Console.WriteLine(Point3D.StartingPoint);

            Point3D p1 = new Point3D(-7, -4, 3);
            Point3D p2 = new Point3D(17, 6, 2.5);

            Console.WriteLine(DistanceCalculator.CalcDistance(p1, p2));

            Path3D path = new Path3D(p1, p2, Point3D.StartingPoint);

            Console.WriteLine(path);

            path.WriteToFile("Path3D.txt");

            Path3D p = Path3D.readPathFromFile("Path3D.txt");

            Console.WriteLine(p.ToString());
        }