static void Main() { Point3D point1 = new Point3D(-7, -4, 3); Point3D point2 = new Point3D(17, 6, 2.5); // Display Points Console.WriteLine("Starting point: " + Point3D.StartingPoint); Console.WriteLine("Point3D 1: " + point1); Console.WriteLine("Point3D 1: " + point2); // Display Distance Between Points double distance = DistanceCalculator.CalculateDistance(point1, point2); Console.WriteLine(); Console.WriteLine("Distance: " + distance); Console.WriteLine(); // Display Path Path3D path = new Path3D(point1, point2); path.AddPoint(new Point3D(4, 6.4, 11.1)); // if 3th value is true, the path will be appended to old file data, else the file will be overwritten Storage.SavePath("paths.txt", path, false); Console.WriteLine("Path: " + path); string storageData = Storage.LoadPath("paths.txt"); Console.WriteLine("\nPath from Storage:\n" + storageData); }
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; }
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]); } }
public static void Load(Path path) { try { using (StreamReader load = new StreamReader(@"..\..\ListOfPoints.txt")) { string line = load.ReadLine(); while (line != null) { int firstCommaIndex = line.IndexOf(','); int secondCommaIndex = line.IndexOf(',', firstCommaIndex + 1); double x = double.Parse(line.Substring(2, firstCommaIndex - 2)); double y = double.Parse(line.Substring(firstCommaIndex + 2, secondCommaIndex - firstCommaIndex - 2)); double z = double.Parse(line.Substring(secondCommaIndex + 2, line.Length - secondCommaIndex - 4)); Point3D point = new Point3D(x, y, z); path.Add(point); line = load.ReadLine(); } } } catch (Exception) { Console.WriteLine("There was a problem loading the path file."); } }
static void Main(string[] args) { List <Point3D.Point3D> path = new List <Point3D.Point3D>(); Point3D.Point3D pointA = new Point3D.Point3D(5, 6, 7); Point3D.Point3D pointB = new Point3D.Point3D(6, 8, 9); Point3D.Point3D pointC = new Point3D.Point3D(11, 13, 20); Point3D.Point3D pointD = new Point3D.Point3D(1, 2, 3); Point3D.Point3D pointE = new Point3D.Point3D(21, 23, 24); path.Add(pointA); path.Add(pointB); path.Add(pointC); path.Add(pointD); path.Add(pointE); //Storage.Save(path); List <Point3D.Point3D> resultFromLoad = Storage.Load(); Console.WriteLine("Loadded Points: "); foreach (var point in resultFromLoad) { Console.WriteLine(point); } }
static void Main(string[] args) { Point3D.Point3D pointA = new Point3D.Point3D(5, 6, 2); Point3D.Point3D pointB = new Point3D.Point3D(-7, 11, -13); Console.WriteLine("The distance between {0} , {1} is: \n{2}", pointA, pointB, DistanceCalculator.CalculateDistance(pointA, pointB)); }
static void Main() { Point3D newPoint = new Point3D(0, 1, 2); Console.WriteLine("Point 1: {0}", newPoint.ToString()); Console.WriteLine(new string('=', 30)); Point3D center = Point3D.GetCoordinateCenter; Console.WriteLine("Start: {0}", center.ToString()); Console.WriteLine(new string('=', 30)); Console.WriteLine("Distance between points = {0:F2}", Distance.Calculate(newPoint, center)); Console.WriteLine(new string('=', 30)); string filePath = "storage.txt"; List<Point3D> points = new List<Point3D>(); points.Add(newPoint); points.Add(center); Path3D path = new Path3D(points); Storage.Save(path, filePath); Path3D readPath = Storage.Load("storage.txt"); int counter = 1; foreach (var point in readPath.Path) { Console.WriteLine("Point {3}: X = {0}, Y = {1}, Z = {2}", point.X, point.Y, point.Z, counter); counter++; } Console.WriteLine(); }
static void Main() { // 1.Create a structure Point3D to hold a 3D-coordinate {X, Y, Z} in the Euclidian 3D space. //Implement the ToString() to enable printing a 3D point. Point3D RandomPoint = new Point3D(1, 2, 3); Console.WriteLine("Random Point:"); Console.WriteLine(RandomPoint.ToString()); // 2. Add a private static read-only field to hold the start of the coordinate system – the point O{0, 0, 0}. // Add a static property to return the point O. Console.WriteLine("Starting Point O:"); Console.WriteLine(Point3D.StartPoint()); //3 Write a static class with a static method to calculate the distance between two points in the 3D space. Point3D PointA = new Point3D(1, 2, 3); Point3D PointB = new Point3D(4, 5, 6); Console.WriteLine("Calculate Distance between two points: "); Console.WriteLine(CalculationDistance.Distance(PointA, PointB)); //4 Create a class Path to hold a sequence of points in the 3D space. //Create a static class PathStorage with static methods to save and load paths from a text file. Use a file format of your choice. Path pathList = new Path(); pathList.path.Add(PointA); pathList.path.Add(PointB); Console.WriteLine("First point of sequence of points"); Console.WriteLine(pathList.path[0]); //Save and load PathStorage.SavePath(pathList); Path LoadedList = PathStorage.LoadPath("../../path.txt"); }
public static void LoadPath() { StreamReader loadPath = new StreamReader(@"..\..\PathLoad.txt"); Path currentPath = new Path(); using (loadPath) { string line = loadPath.ReadLine(); while (line != null) { string[] coordinates = line.Split(' '); Point3D newPoint = new Point3D(int.Parse(coordinates[0]), int.Parse(coordinates[1]), int.Parse(coordinates[2])); currentPath.AddPath(newPoint); line = loadPath.ReadLine(); } } //foreach (var item in currentPath.sequenceOfPoints) //{ // Console.WriteLine(item); //} }
static void Main() { //Create new point Point3D myPoint = new Point3D(2, 3, 4); Console.WriteLine(myPoint); Console.WriteLine(Point3D.Point0); //Calculate distance between two points double distance = PointCalculations.Point3DDistance(Point3D.Point0, myPoint); Console.WriteLine(distance); //Create new path and add elements Path testPath = new Path(myPoint); testPath.AddToPath(Point3D.Point0); //Save path in file PathStorage.SaveInFile(testPath); //Create new path and add points from file Path readTest = new Path(); readTest = PathStorage.ReadFromFile(); //Print readed from file points List<Point3D> points = new List<Point3D>(); points = readTest.GetAllPathElements(); foreach (var item in points) { Console.WriteLine(item); } }
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); } } }
public static double CalcDistance(Point3D one, Point3D two) { double result = Math.Sqrt(Math.Pow((one.XCoord - two.XCoord), 2) + Math.Pow((one.YCoord - two.YCoord), 2) + Math.Pow((one.ZCoord - two.ZCoord), 2)); return result; }
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(); }
public static void Main() { // Adding some paths to save in file Point3D path = new Point3D(1, 4, 7); Path current = new Path(); current.AddPath(path); path = new Point3D(1, 74, 78); current.AddPath(path); path = new Point3D(18, 14, 8); current.AddPath(path); path = new Point3D(100, 84, 47); current.AddPath(path); path = new Point3D(47, 94, 0); current.AddPath(path); PathStorage.SavePath(current); Console.WriteLine("The paths are saved in PathSave.txt"); // Uncomment the foreach cycle in PathStorage.cs to print the path readed from PathLoad.txt PathStorage.LoadPath(); }
public static double CalculateDistance(Point3D firstPoint, Point3D secondPoint) { double xdistance = (secondPoint.X - firstPoint.X) * (secondPoint.X - firstPoint.X); double ydistance = (secondPoint.Y - firstPoint.Y) * (secondPoint.Y - firstPoint.Y); double zdistance = (secondPoint.Z - firstPoint.Z) * (secondPoint.Z - firstPoint.Z); return Math.Sqrt(xdistance + ydistance + zdistance); }
static void Main(string[] args) { Point3D pointA = new Point3D(0, 0, 0); Point3D pointB = new Point3D(1, 1, 1); Console.WriteLine(pointA); Console.WriteLine(pointB); Point3D a = Point3D.StartPoint; Console.WriteLine(a); double result = DistanceCalculator.CalcDistance(pointA, pointB); Console.WriteLine(result); Path3D path = new Path3D(new List<Point3D>() { new Point3D(0,0,0), new Point3D(1,2,3), new Point3D(2,2,2), new Point3D(1,4,5), new Point3D(4,7,8) }); Storage.SaveFile(path.ReturnPoints); var load = Storage.LoadFile("Points.txt"); Path3D secPath = new Path3D(load); }
public static double CalculateDistance(Point3D pointOne, Point3D pointTwo) { double deltaX = pointOne.x - pointTwo.x; double deltaY = pointOne.y - pointTwo.y; double deltaZ = pointOne.z - pointTwo.z; return Math.Sqrt((deltaX * deltaX) + (deltaY * deltaY) + (deltaZ * deltaZ)); }
public static void Main() { Point3D firstPoint = new Point3D(3, 5, 9); Point3D secondPoint = new Point3D(4, 5, 19); double distance = DistanceCalculator.CalculateDistance(firstPoint, secondPoint); Console.WriteLine("{0:F2}", distance); }
public static void Main() { Point3D firstPoint = new Point3D(); Point3D secondPoint = new Point3D(2.5, 55556, 8); firstPoint.X = 5; Console.WriteLine(firstPoint.ToString()); Point3D beginning = Point3D.StartignPoint; Console.WriteLine("The beginning of the coordinate system is {0}", beginning.ToString()); double distance = DistanceCalculator.BetweenTwoPointsIn3D(beginning, firstPoint); Console.WriteLine("The distance between them is: " + distance); Console.WriteLine(); Path3D path1 = new Path3D(firstPoint, secondPoint, beginning, firstPoint); Console.Write("Enter path name: "); string pathName = Console.ReadLine(); while (!Storage.WritePath(path1, pathName)) { Console.Write("Path with that name already exists. Enter diffrent name:"); pathName = Console.ReadLine(); } Console.WriteLine("File successfully created.\n"); Path3D path2 = new Path3D(beginning, firstPoint, secondPoint); Storage.WritePath(path2, "Path2"); Console.WriteLine(Storage.ReadPath("Path2")); Console.WriteLine(); Console.WriteLine(Storage.ReadPath("Path")); }
/*In 3D Define your two points. Point 1 at (x1, y1, z1) and Point 2 at (x2, y2, z2). xd = x2-x1 yd = y2-y1 zd = z2-z1 Distance = SquareRoot(xd*xd + yd*yd + zd*zd) */ public static double CalculateDistanceBetweenTwoPoints(Point3D point1, Point3D point2) { double distance; int xd = (point2.X - point1.X); int yd = (point2.Y - point1.Y); int zd = (point2.Z - point1.Z); return distance = Math.Sqrt((double)(xd * xd + yd * yd + zd * zd)); }
public static double CalculateDistance3D(Point3D firstPoint, Point3D secondPoint) { double result = Math.Sqrt(Math.Pow(firstPoint.X-secondPoint.X,2)+ Math.Pow(firstPoint.Y-secondPoint.Y,2)+ Math.Pow(firstPoint.Z-secondPoint.Z,2)); return result; }
public static float CalculateD(Point3D a, Point3D b) { float deltaX = a.X - b.X; float deltaY = a.Y - b.Y; float deltaZ = a.Z - b.Z; return (float)Math.Sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ); }
public static double CalculateDistance(Point3D firstPoint, Point3D secondPoint) { double distance = Math.Sqrt((firstPoint.X - secondPoint.X) * (firstPoint.X - secondPoint.X) + (firstPoint.Y - secondPoint.Y) * (firstPoint.Y - secondPoint.Y) + (firstPoint.Z - secondPoint.Z) * (firstPoint.Z - secondPoint.Z)); return distance; }
public static decimal CalculateDistance(Point3D p1, Point3D p2) { decimal distance = (decimal)Math.Sqrt( (p1.X - p2.X) * (p1.X - p2.X) + (p1.Y - p2.Y) * (p1.Y - p2.Y) + (p1.Z - p2.Z) * (p1.Z - p2.Z)); return distance; }
public static double FindDistance(Point3D p1, Point3D p2) { int xd = p2.X - p1.X; int yd = p2.Y - p1.Y; int zd = p2.Z - p1.Z; return Math.Sqrt(xd*xd + yd*yd + zd*zd); }
public static double CalculateDistance(Point3D.Point3D pointA, Point3D.Point3D pointB) { double distance = Math.Sqrt(Math.Pow((pointB.X - pointA.X), 2) + Math.Pow((pointB.Y - pointA.Y), 2) + Math.Pow((pointB.Z - pointA.Z), 2)); return(distance); }
public static double Calculate(Point3D point1, Point3D point2) { double deltaX = point1.X - point2.X; double deltaY = point1.Y - point2.Y; double deltaZ = point1.Z - point2.Z; return Math.Sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ); }
public static double CalculateDistanceOfTwoPoints(Point3D firstPoint, Point3D secondPoint) { double coordinatesX = (firstPoint.X - secondPoint.X) * (firstPoint.X - secondPoint.X); double coordinatesY = (firstPoint.Y - secondPoint.Y) * (firstPoint.Y - secondPoint.Y); double coordinatesZ = (firstPoint.Z - secondPoint.Z) * (firstPoint.Z - secondPoint.Z); return Math.Sqrt(coordinatesX + coordinatesY + coordinatesZ); }
public static decimal CalcBetween(Point3D a, Point3D b) { decimal distance = 0.0m; decimal distanceX = a.CoordX - b.CoordX; decimal distanceY = a.CoordY - b.CoordY; decimal distanceZ = a.CoordZ - b.CoordZ; distance = (decimal)Math.Sqrt((double)(distanceX*distanceX + distanceY*distanceY + distanceZ*distanceZ)); return distance; }
/* Problem 2. Distance Calculator Write a static class DistanceCalculator with a static method to calculate the distance between two points in the 3D space. Search in Internet how to calculate distance in the 3D Euclidian space. Damn it this Math: http://freespace.virgin.net/hugo.elias/routines/r_dist.htm */ public static double CalcDistance(Point3D.StructPoint3D firstPoint, Point3D.StructPoint3D secondPoint) { var distance = Math.Round(Math.Sqrt( Math.Pow(secondPoint.X - firstPoint.X, 2) + Math.Pow(secondPoint.Y - firstPoint.Y, 2) + Math.Pow(secondPoint.Z - firstPoint.Z, 2)), 2); return distance; }
public static double CalculateDistanceBetween3DPoints(Point3D first, Point3D second) { double xDistance = Math.Pow((second.X - first.X), (second.X - first.X)); double yDistance = Math.Pow((second.Y - first.Y), (second.Y - first.Y)); double zDistance = Math.Pow((second.Z - first.Z), (second.Z - first.Z)); double distance = Math.Sqrt(xDistance + yDistance + zDistance); return distance; }
public static double CalcDistance(Point3D pointA, Point3D pointB) { double deltaX = pointB.X - pointA.X; double deltaY = pointB.Y - pointA.Y; double deltaZ = pointB.Z - pointA.Z; double distance = (double)Math.Sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ); return distance; }
public static void Main(string[] args) { Point3D a = new Point3D(2, 2, 2); Point3D b = new Point3D(3, 3, 3); var list = new List<Point3D>(); list.Add(a); list.Add(b); Path3D path = new Path3D(list); Storage.Save(path); }
public static List <Point3D.Point3D> Load() { List <Point3D.Point3D> listOfPoints = new List <Point3D.Point3D>(); using (StreamReader file = new StreamReader(path)) { string line = ""; while ((line = file.ReadLine()) != null) { line = line.Replace('{', ' '); line = line.Replace('}', ' '); line = line.Replace(" ", ""); string[] lineArgs = line.Split(new char[] { ',' }); Point3D.Point3D point = new Point3D.Point3D(double.Parse(lineArgs[0]), double.Parse(lineArgs[1]), double.Parse(lineArgs[2])); listOfPoints.Add(point); } } return(listOfPoints); }