public static Path LoadPath(string fileName) { if (!File.Exists(fileName)) { throw new FileNotFoundException("{0} cannot be found", fileName); } Path path = new Path(); using (StreamReader fileReader = new StreamReader(fileName)) { string line; while ((line = fileReader.ReadLine()) != null) { string[] coordinates = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); int x, y, z; if (coordinates.Length == 3 && int.TryParse(coordinates[0], out x) && int.TryParse(coordinates[1], out y) && int.TryParse(coordinates[2], out z)) { Point3D point = new Point3D(x, y, z); path.Add(point); } } } return path; }
static void Main(string[] args) { Point3D pt = new Point3D(0,1,0); Console.WriteLine(Point3D.DefaultPoint); Console.WriteLine(Distance.CalculateDistance(Point3D.DefaultPoint, pt)); Path path = new Path(); path.Add(pt); path.Add(Point3D.DefaultPoint); PathStorage.SavePath(path, "path.txt"); }
public static double CalculateDistance(Point3D firstPoint, Point3D secondPoint) { return Math.Sqrt(Math.Abs((firstPoint.X - secondPoint.X)*(firstPoint.X - secondPoint.X) + (firstPoint.Y - secondPoint.Y)*(firstPoint.Y - secondPoint.Y) + (firstPoint.Z - secondPoint.Z)*(firstPoint.Z - secondPoint.Z))); }
public void Add(Point3D point) { pathList.Add(point); }