public static void Main() { // creating two instances of the Point3D class and printing the on the console // to check if printing is correct var firstPoint = new Point3D(1.05, 2.14, 3.14); var secondPoint = new Point3D(17, 6, 2); Console.WriteLine(firstPoint); Console.WriteLine(secondPoint); // calculating distance between the two points using the static class DistanceCalculator // according to online 3D distance calculator distance should be 16.449976 // with precision of six digits after the decimal point var distance = DistanceCalculator.CalculateDistance(firstPoint, secondPoint); Console.WriteLine("Distance between the two points: {0:f6}", distance); // create an instance of the class path try to print add some point in it // and output them on the console var thirdPoint = new Point3D(12, 12, 12); var totalPoints = new Path(); totalPoints.AddPoint(firstPoint); totalPoints.AddPoint(secondPoint); totalPoints.AddPoint(thirdPoint); Console.WriteLine(totalPoints); Console.WriteLine(); // use the static method SavePath() in PathStorage class to try and save a given path in a text // file. The result of the method should be saved in save.txt in the "coordinates" // folder PathStorage.SavePath(totalPoints, @"..\..\SavedPoints.txt"); // use static method LoadPath to load a sequence of points and add them to an // instance of the Path class var loadedPath = PathStorage.LoadPath(@"..\..\PointsToLoad.txt"); Console.WriteLine(); Console.WriteLine(loadedPath); }
public static Path LoadPaths(string filePath) { Path listOfPaths = new Path(); StreamReader reader = new StreamReader(filePath); using (reader) { string line = reader.ReadLine(); while (line != null) { double[] coordinates = line.Split(' ').Select(double.Parse).ToArray(); Point3D point = new Point3D(coordinates[0], coordinates[1], coordinates[2]); listOfPaths.AddPoint(point); line = reader.ReadLine(); } } return listOfPaths; }
public static Path LoadPath(string directory) { var path = new Path(); using (var reader = new StreamReader(directory)) { string currentLine = reader.ReadLine(); while (currentLine != null) { var currentPointArgs = currentLine .Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(double.Parse).ToArray(); var currentPoint = new Point3D(currentPointArgs[0], currentPointArgs[1], currentPointArgs[2]); path.AddPoint(currentPoint); currentLine = reader.ReadLine(); } } return(path); }