示例#1
0
        static void Main(string[] args)
        {
            Point3D start = Point3D.StartPoint;
            Point3D a = new Point3D(1, 1, 1);
            Point3D b= new Point3D(2.1, 2, 3.4);
            double distanceStartA = DistanceCalculator.DistanceBetweenPoint3D(start, a);
            double distanceStartB = DistanceCalculator.DistanceBetweenPoint3D(start, b);
            Path3D first = new Path3D(start, a);
            Path3D second = new Path3D(start, a, b);
            Storage.SavePath(first, "pathFirst.txt");
            Storage.SavePath(second, "pathSecond.txt");

            try
            {
                Path3D loadedFirst = Storage.LoadPath("pathFirst.txt");
                foreach (Point3D point in loadedFirst.Points)
                {
                    Console.WriteLine("{0} {1} {2}",point.X,point.Y,point.Z);
                }
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine(e.Message);
            }
        }
示例#2
0
        public static void SavePath(Path3D path, String filePath)
        {
            Stream file = File.Create(filePath);
            StreamWriter writer =  new StreamWriter(file);
            using (writer)
            {

                foreach (Point3D point in path.Points)
                {
                    writer.WriteLine("{0} {1} {2}", point.X, point.Y, point.Z);
                }
            }
        }
示例#3
0
 public static Path3D LoadPath(String filename)
 {
     List<Point3D> points =new List<Point3D>();
     StreamReader reader=new StreamReader(filename);
     using(reader)
     {
         while(true)
         {
             String line=reader.ReadLine();
             if(string.IsNullOrEmpty(line))
             {
                 break;
             }
             double[] coordinates=line.Split(' ').Select(double.Parse).ToArray();
             double x=coordinates[0];
             double y=coordinates[1];
             double z=coordinates[2];
             points.Add(new Point3D(x,y,z));
         }
     }
     Path3D path=new Path3D(points.ToArray());
     return path;
 }