public static void Main() { //test struct 3D Point3D point = new Point3D(1, 2, 3); Point3D pointTwo = new Point3D(4, 5, 6); double distBtw2Poins = CalculateDistance.CalcDist(point, pointTwo); Console.WriteLine("The distance between 2 point is {0}",distBtw2Poins); //testing PathStorage //write Path pathToWrite = new Path(); pathToWrite.AddPoint(point); pathToWrite.AddPoint(pointTwo); PathStorage.SavePath(pathToWrite); Console.WriteLine(); Console.WriteLine("Check the project folder for saved file."); Console.WriteLine(); //read List<Path> readedPath = PathStorage.LoadPath(); Console.WriteLine("This is the points from readed file:" ); foreach (var path in readedPath) { foreach (var pointers in path.PathOfPoints) { Console.WriteLine(pointers); } } }
static void Main() { /*наясно съм че "Point3D ex1-ex2-ex3-ex4" не е добро наименование на проект, * правилно е да е "Point3D", добавих единствено това "ex1-ex2-ex3-ex4", * за да е прегледно за проверяващия кои задачи обхваща от домашното*/ string fileName = @"../../../paths.txt"; //string fileName = "c://test//path.txt"; //wrong path //ex.1 Point3D point = new Point3D(3, 5, 7); Console.WriteLine(point.ToString()); //ex.2 print zero point Point3D point1 = Point3D.Zero; Console.WriteLine(point1.ToString()); //ex.3 print distance between two points Console.WriteLine("The distance between two pints is: {0:F8}", DistanceIn3DSpace.CalculateDistanceBetweenTwoPoints(point, point1)); //ex.4 add point in path Path pathOfPoints = new Path(); pathOfPoints.AddPoint(point); pathOfPoints.AddPoint(point1); //write paths in file PathStorage.SavePathsInFile(pathOfPoints, fileName); //load paths from file Path pathOfPointsLoad = new Path(); pathOfPointsLoad = PathStorage.LoadPathsFromFile(fileName); Console.WriteLine("Print points from pathOfPointsLoad"); pathOfPointsLoad.PrintPaths(); }
static void Main() { Path pointsPath = new Path(); pointsPath.AddPoint(new Point(1.32, 2.22, 3.12)); pointsPath.AddPoint(new Point(3.32, 2.22, 1.12)); pointsPath.AddPoint(new Point(4.31, 5.22, 6.13)); pointsPath.AddPoint(new Point(5.37, 4.28, 3.19)); Console.WriteLine(Point.StartingPoint); Console.WriteLine(DistanceCalculator.CalcDistance(pointsPath.Points[0], pointsPath.Points[1])); foreach (var point in pointsPath.Points) { Console.WriteLine(point.ToString()); } string fileLocation = "../../path"; Storage.WriteToBinaryFile(fileLocation, pointsPath); Console.WriteLine("\r\nPoints from file:"); Path pathFromFile = Storage.ReadFromBinaryFile<Path>(fileLocation); foreach (var point in pathFromFile.Points) { Console.WriteLine(point.ToString()); } }
static void Main() { Point3D point1 = new Point3D(1.5, 2.5, 3.5); //creating points for testing purposes Point3D point2 = new Point3D(-1, -4, 7); Point3D point3 = new Point3D(1, 2, 3); Point3D point4 = new Point3D(-1, -2, 3); Point3D point5 = new Point3D(1.25, 2.375, 3.8); Path testPath = new Path(); //creating a path of points for testing purposes testPath.AddPoint(point1); testPath.AddPoint(point2); testPath.AddPoint(point3); testPath.AddPoint(point4); testPath.AddPoint(point5); PathStorage.SavePath(testPath, "test"); //saving the test points to the file "test.txt" Console.WriteLine("Test file has been created"); Console.WriteLine(new string('-', 50)); Path loadedPath = PathStorage.LoadPath(@"../../test.txt"); //loading the saved file and printing the points for (int i = 0; i < loadedPath.PointSequence.Count; i++) { Console.WriteLine(loadedPath.PointSequence[i]); } }
static void Main(string[] args) { Structure3D firstPoint = new Structure3D(1, 2, 3); Structure3D secondPoint = new Structure3D(0, 8, 1); Path firstPath = new Path(); firstPath.AddPoint(firstPoint); firstPath.AddPoint(secondPoint); PathStorage.SavePaths(firstPath); List<Path> pathList = PathStorage.ReadPaths(); }
public static void Test4() { Path test1 = new Path(); test1.AddPoint(); test1.AddPoint(new Point(1, 2, 3)); test1.AddPoint(4, 5, 6); Console.WriteLine(test1); // testing toString for a path PathStorage.WritePathToFile("testing.txt", test1); Path readFromFile = PathStorage.ReadPathFromFile("readMe.txt"); Console.WriteLine(readFromFile); }
public static List<Path> LoadPathsFromFile() { var paths = new List<Path>(); var pathReader = new StreamReader(LoadFilePath); using (pathReader) { int numberOfPaths = int.Parse(pathReader.ReadLine()); for (int i = 0; i < numberOfPaths; i++) { int numberOfPointsinPath = int.Parse(pathReader.ReadLine()); var path = new Path(); string[] currentLine; for (int k = 0; k < numberOfPointsinPath; k++) { currentLine = pathReader.ReadLine().Split(new[] { ", " }, StringSplitOptions.RemoveEmptyEntries); double x = double.Parse(currentLine[0]); double y = double.Parse(currentLine[1]); double z = double.Parse(currentLine[2]); path.AddPoint(new Point3D(x, y, z)); } paths.Add(path); } } return paths; }
public static Path LoadPath(string pathToFile) { if (pathToFile == string.Empty || !File.Exists(pathToFile)) { throw new ArgumentException("The path is wrong or file doesn't exist!"); } StreamReader read = new StreamReader(pathToFile); Path pointsSpace = new Path(); string line; using (read) { line = read.ReadLine(); while (line != null) { string[] coordinates = line.Split(new char[] { ' ', ','}, StringSplitOptions.RemoveEmptyEntries); Structure3DPoint point = new Structure3DPoint(int.Parse(coordinates[0]), int.Parse(coordinates[1]), int.Parse(coordinates[2])); pointsSpace.AddPoint(point); line = read.ReadLine(); } } return pointsSpace; }
public static List<Path> LoadPath() { Path loadPath = new Path(); List<Path> pathsLoaded = new List<Path>(); using (StreamReader reader = new StreamReader(@"PathLoads.txt")) { string line = reader.ReadLine(); while (line != null) { if (line != "-") { Point3D point = new Point3D(); string[] points = line.Split(','); point.X = int.Parse(points[0]); point.Y = int.Parse(points[1]); point.Z = int.Parse(points[2]); loadPath.AddPoint(point); } else { pathsLoaded.Add(loadPath); loadPath = new Path(); } line = reader.ReadLine(); } } return pathsLoaded; }
public static void Main() { var firstPoint = new Point3D(1, 2, 3); var secondPoint = new Point3D(2, 3, 4); var thirdPoint = new Point3D(3, 4, 5); var forthPoint = new Point3D(4, 5, 6); Console.WriteLine("Created 4 test point and printing them on the console:"); Console.WriteLine(firstPoint); Console.WriteLine(secondPoint); Console.WriteLine(thirdPoint); Console.WriteLine(forthPoint); Console.WriteLine("\nPrintitng start point:"); Console.WriteLine(Point3D.StartPoint); Console.WriteLine("\nCalculating the distance between the two points:"); Console.WriteLine(firstPoint); Console.WriteLine(secondPoint); Console.WriteLine("Distance: " + Point3DCalculations.CalculateDistance(firstPoint, secondPoint)); var firstPath = new Path(); firstPath.AddPoint(firstPoint); firstPath.AddPoint(secondPoint); var secondPath = new Path(); secondPath.AddPoint(thirdPoint); secondPath.AddPoint(forthPoint); var paths = new List <Path>(); paths.Add(firstPath); paths.Add(secondPath); PathStorage.SavePathsToFile(paths); Console.WriteLine("\nSucssesfuly saved paths to the following file:\n " + System.IO.Path.GetFullPath(PathStorage.SaveFilePath)); var pathsLoadedFromFile = PathStorage.LoadPathsFromFile(); Console.WriteLine("\nPrinting the points read from the paths saved in the following file:\n " + System.IO.Path.GetFullPath(PathStorage.LoadFilePath)); foreach (var path in pathsLoadedFromFile) { foreach (var point3d in path.PointsPath) { Console.WriteLine(point3d.ToString()); } } }
static void Main() { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; var pointsSequence = new Path(); Point3D firstPoint3D = new Point3D(1.2, 2.4, 3.7); pointsSequence.AddPoint(firstPoint3D); Console.WriteLine("Point({0})", firstPoint3D); Point3D secondPoint3D = Point3D.StartPoint; pointsSequence.AddPoint(secondPoint3D); Console.WriteLine("Point({0})", secondPoint3D); Console.WriteLine("Distance between the points: {0:F2}", Distance.CalcDistance(firstPoint3D, secondPoint3D)); pointsSequence.RemovePoint(firstPoint3D); pointsSequence.RemovePoint(secondPoint3D); Path path3D = new Path(); string[] points = File.ReadAllText(@"..\..\input.txt").Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); File.WriteAllText(@"..\..\output.txt", string.Empty); Console.WriteLine("\nPoints loaded from input.txt"); int index = 0; while (index < points.Length) { double[] coordinates = points[index].Split(new[] { ", " }, StringSplitOptions.RemoveEmptyEntries) .Select(double.Parse) .ToArray(); path3D.AddPoint(new Point3D(coordinates[0], coordinates[1], coordinates[2])); Console.WriteLine("{0}", path3D.PointsSequence[index]); File.AppendAllText(@"..\..\output.txt", points[index] + Environment.NewLine); index++; } Console.WriteLine("Points saved to output.txt\n"); }
static void Main(string[] args) { // Examples Point3D p1 = new Point3D(5.4, 6.2, 3); Point3D p2 = new Point3D(7.9, 2.1, 5.9); Point3D p3 = new Point3D(23.4, 3, 5); Point3D p4 = new Point3D(7, 15.5, 57.7); // Create sequence of points ( List<Point3D> ) Path points = new Path(); Console.WriteLine("The Path of 3D points is created.\n"); // Add points in the sequence Console.WriteLine("Adding some 3D points..."); points.AddPoint(p1); points.AddPoint(p2); points.AddPoint(p3); points.AddPoint(p4); Console.WriteLine(points); //Remove some points Console.WriteLine("\nRemoving first and last 3D point from tha Path...\n"); points.RemovePoint(p1); points.RemovePoint(p4); Console.WriteLine("Now the Path contains:"); Console.WriteLine(points.ToString()); // Calculate distance between two 3D points Console.WriteLine("\nCalculate the distance between two 3D points:\n"); Console.WriteLine("{0:F2} cm", DistanceCalculator.CalculateDistance(p2, p3)); // Save points into text file PathStorage.SavePaths(points, "PointsFromText.txt"); Console.WriteLine("\nThe Path of 3D Points is saved in text file."); Console.WriteLine("You can find it at: Current Project\\bin\\Debug\\PointsFromText.txt"); }
public static void Main() { var firstPoint = new Point3D(1, 2, 3); var secondPoint = new Point3D(2, 3, 4); var thirdPoint = new Point3D(3, 4, 5); var forthPoint = new Point3D(4, 5, 6); Console.WriteLine("Created 4 test point and printing them on the console:"); Console.WriteLine(firstPoint); Console.WriteLine(secondPoint); Console.WriteLine(thirdPoint); Console.WriteLine(forthPoint); Console.WriteLine("\nPrintitng start point:"); Console.WriteLine(Point3D.StartPoint); Console.WriteLine("\nCalculating the distance between the two points:"); Console.WriteLine(firstPoint); Console.WriteLine(secondPoint); Console.WriteLine("Distance: " + Point3DCalculations.CalculateDistance(firstPoint, secondPoint)); var firstPath = new Path(); firstPath.AddPoint(firstPoint); firstPath.AddPoint(secondPoint); var secondPath = new Path(); secondPath.AddPoint(thirdPoint); secondPath.AddPoint(forthPoint); var paths = new List<Path>(); paths.Add(firstPath); paths.Add(secondPath); PathStorage.SavePathsToFile(paths); Console.WriteLine("\nSucssesfuly saved paths to the following file:\n " + System.IO.Path.GetFullPath(PathStorage.SaveFilePath)); var pathsLoadedFromFile = PathStorage.LoadPathsFromFile(); Console.WriteLine("\nPrinting the points read from the paths saved in the following file:\n " + System.IO.Path.GetFullPath(PathStorage.LoadFilePath)); foreach (var path in pathsLoadedFromFile) { foreach (var point3d in path.PointsPath) { Console.WriteLine(point3d.ToString()); } } }
public static void Main() { var point = new Point3D(4.5, 8.4, 9.6); var anotherPoint = new Point3D(5.8, 9.7, 0.3); double distance = PointDistance.Distance(point, anotherPoint); Console.WriteLine(distance); Console.WriteLine(point); Console.WriteLine(Point3D.PointO); Console.WriteLine(new string('-', 50)); Path testPath = new Path(); Point3D point1 = new Point3D(1.5, 2.5, 3.5); Point3D point2 = new Point3D(-1, 2, 7); Point3D point3 = new Point3D(4, 2, 3); Point3D point4 = new Point3D(-5, -4, 3); Point3D point5 = new Point3D(1.25, 2.375, 3); testPath.AddPoint(point1); testPath.AddPoint(point2); testPath.AddPoint(point3); testPath.AddPoint(point4); testPath.AddPoint(point5); PathStorage.SavePath(testPath, "sample"); Path loadedPath = PathStorage.LoadPath(@"../../pointsample.txt"); Console.WriteLine("The points from the text file are: "); for (int i = 0; i < loadedPath.PointList.Count; i++) { Console.WriteLine("Point {0}: {1}", i + 1, loadedPath.PointList[i].ToString()); } }
public static Path LoadPath(string filePath) { Path path = new Path(); using (StreamReader sr = new StreamReader(filePath)) { while (sr.EndOfStream == false) { string nextPointTxt = sr.ReadLine(); Point3D nextPoint = Point3D.Parse(nextPointTxt); path.AddPoint(nextPoint); } } return(path); }
public static Path LoadPath(string filePath) { Path path = new Path(); using (StreamReader sr = new StreamReader(filePath)) { while (sr.EndOfStream == false) { string nextPointTxt = sr.ReadLine(); Point3D nextPoint = Point3D.Parse(nextPointTxt); path.AddPoint(nextPoint); } } return path; }
public static Path ReadPathFromFile(string fileLocation) { Path generatedPath = new Path(); StreamReader reader = new StreamReader(fileLocation); using (reader) { string currLine = reader.ReadLine(); while (currLine != null) { currLine = currLine.Substring(currLine.IndexOf("-->") + 3); int[] coords = currLine.Split(new char[] { ',', ' '}, StringSplitOptions.RemoveEmptyEntries) .Select(int.Parse).ToArray(); generatedPath.AddPoint(coords[0], coords[1], coords[2]); currLine = reader.ReadLine(); } } return generatedPath; }
static void Main() { //just for testing the classes and structures Path newPath = PathStorage.LoadFile(); Point3DCoordinates point = new Point3DCoordinates(1, 2, 6); newPath.AddPoint(point); foreach (var item in newPath.path) { Console.WriteLine(item.ToString()); } PathStorage.SaveFile(newPath); Point3DCoordinates first = new Point3DCoordinates(1, 2, 3); Point3DCoordinates second = new Point3DCoordinates(1, 5, 8); Console.WriteLine(Distance.DistanceBetweenPoints(first, second)); }
public static Path ReadPathFromFile(string fileLocation) { Path generatedPath = new Path(); StreamReader reader = new StreamReader(fileLocation); using (reader) { string currLine = reader.ReadLine(); while (currLine != null) { currLine = currLine.Substring(currLine.IndexOf("-->") + 3); int[] coords = currLine.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(int.Parse).ToArray(); generatedPath.AddPoint(coords[0], coords[1], coords[2]); currLine = reader.ReadLine(); } } return(generatedPath); }
public static Path LoadPathsFromFile(string fileName) { //fileName = @"../../../paths.txt"; StreamReader loadFile = new StreamReader(fileName); Path loadPath = new Path(); try { using (loadFile) { while (loadFile.Peek() >= 0) { String line = loadFile.ReadLine(); String[] splittedLine = line.Split(new char[] { '(', ',', ')' }, StringSplitOptions.RemoveEmptyEntries); loadPath.AddPoint(new Point3D(int.Parse(splittedLine[0]), int.Parse(splittedLine[1]), int.Parse(splittedLine[2]))); } } } catch (DirectoryNotFoundException dirEx) { Console.WriteLine("NOT FOUND {0}, {1}",dirEx.Message, dirEx.StackTrace); } catch (FileNotFoundException fileEx) { Console.WriteLine(fileEx.Message, fileEx.StackTrace); } catch (FileLoadException fileLoadEx) { Console.WriteLine(fileLoadEx.Message, fileLoadEx.StackTrace); } catch (IOException ioEx) { Console.WriteLine(ioEx.Message, ioEx.StackTrace); } catch (Exception ex) { Console.WriteLine(ex.Message, ex.StackTrace); } return loadPath; }
public static List<Path> LoadPath() { StreamReader reader = new StreamReader(@"../../LoadPoints.txt"); Path newList = new Path(); List<Path> pathLoaded = new List<Path>(); using (reader) { string lineOfText = reader.ReadLine(); while (lineOfText!=null) { string[] coordinates = lineOfText.Split(new char[]{','}, StringSplitOptions.RemoveEmptyEntries); Point3D point = new Point3D(); point.X = int.Parse(coordinates[0]); point.Y = int.Parse(coordinates[1]); point.Z = int.Parse(coordinates[2]); newList.AddPoint(point); lineOfText = reader.ReadLine(); } pathLoaded.Add(newList); } return pathLoaded; }
public static List<Path> ReadPaths() { Path readPaths = new Path(); List<Path> pathsLoaded = new List<Path>(); string pathRead = "Paths.txt"; StreamReader reader = new StreamReader(pathRead); using (reader) { string line = reader.ReadLine(); while (line != null) { Structure3D point = new Structure3D(); string[] points = line.Split(','); point.PositionX = int.Parse(points[0]); point.PositionY = int.Parse(points[1]); point.PositionZ = int.Parse(points[2]); readPaths.AddPoint(point); line = reader.ReadLine(); } } return pathsLoaded; }