public static double CalcDistance3D(Point3D firstPoint, Point3D secondPoint) { double distance = Math.Sqrt((firstPoint.X - secondPoint.X) * (firstPoint.X - secondPoint.X) + (firstPoint.Y - secondPoint.Y) * (firstPoint.Y - secondPoint.X) + (firstPoint.Z - secondPoint.Z) * (firstPoint.Z - secondPoint.Z)); return distance; }
public static double GetDistance(Point3D p1, Point3D p2) { var xd = p2.X - p1.X; var yd = p2.Y - p1.Y; var zd = p2.Z - p1.Z; return Math.Sqrt(xd*xd + yd*yd + zd*zd); }
public static Path LoadPath(string fileFullName) { if (String.IsNullOrWhiteSpace(fileFullName)) { throw new ArgumentException("File name cannot be null or empty."); } if (!File.Exists(fileFullName)) { throw new ArgumentException("The specified file doesn't exist in the local file system."); } Path points = new Path(); using (StreamReader fileReader = new StreamReader(fileFullName)) { string line; while ((line = fileReader.ReadLine()) != null) { string[] coordinates = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); double x, y, z; if (coordinates.Length == 3 && Double.TryParse(coordinates[0], out x) && Double.TryParse(coordinates[1], out y) && Double.TryParse(coordinates[2], out z)) { Point3D point = new Point3D(x, y, z); points.Add(point); } } } return points; }
public static double GetDistance3DPoints(Point3D point1, Point3D point2) { double distance = 0; distance = Math.Sqrt((point1.x - point2.x) * (point1.x - point2.x) + (point1.y - point2.y) * (point1.y - point2.y) + (point1.z - point2.z) * (point1.z - point2.z)); return distance; }
internal static void Main() { Point3D pointZero = Point3D.StartingPoint3D; Point3D pointOne = new Point3D(1, 1, 1); Point3D pointTwo = new Point3D(2, 2, 2); Console.WriteLine("The distance between point 0 and 1 is {0:0.00}", DistanceCalculator.CalcDist(pointZero, pointOne)); Console.WriteLine("The distance between point 0 and 2 is {0:0.00}", DistanceCalculator.CalcDist(pointZero, pointTwo)); }
public void TestPath() { Path points = new Path(); Point3D point = new Point3D(2, -5, 7); points.Add(point); Assert.AreEqual(2, point.X); Assert.AreEqual(-5, point.Y); Assert.AreEqual(7, point.Z); }
static void Main(string[] args) { Point3D pointA = new Point3D(21,10,15); Point3D pointB = new Point3D(); Console.WriteLine(CalcDistance.CalculateDistanceBetweenTwoPoints(pointA, pointB)); Point3D pointC = Point3D.PointO; Path shortPath = new Path(); shortPath.AddPoint(pointA); shortPath.AddPoint(pointC); PathStorage.PathSave(shortPath); PathStorage.PathLoad(@"../../path.txt"); }
public void TestCalcDistance() { Path points = new Path(); Point3D point1 = new Point3D(0, 0, 0); points.Add(point1); Point3D point2 = new Point3D(1, 1, 0); points.Add(point2); double distance = DistanceFinder.CalcDistance(points[1], points[0]); Assert.AreEqual(1.41, Math.Round(distance, 2)); }
static void Main() { // Test creating a new instance of Point3D Point3D myPoint = new Point3D(2, 2, 2); // Test the override of ToString() Console.WriteLine(myPoint.ToString()); // Test the static property PointO Console.WriteLine(Point3D.PointO.ToString()); // Test the calculating of distance between two points Console.WriteLine("The distance between {0} and {1} is: {2}",myPoint, Point3D.PointO, Distance3D.CalcDistance3D(myPoint, Point3D.PointO)); }
internal static void Main() { Point3D pointZero = Point3D.StartingPoint3D; Point3D pointOne = new Point3D(1.0, 1.0, 1.0); Point3D pointTwo = new Point3D(2.0, 2.0, 2.0); Point3D[] points = new Point3D[] { pointZero, pointOne, pointTwo }; foreach (Point3D point in points) { Console.WriteLine(point); } }
static void Main() { Point3D point1 = new Point3D(0.4, 1.5, 2.34); //creates some new points Point3D point2 = new Point3D(1.6, 2.5, 3.67); Point3D point3 = new Point3D(-2.56, -5, -1.4); Point3D point4 = new Point3D(2.3, 6, -4.2); Console.WriteLine(point1.ToString()); //prints one of the points to test overridden ToString() method //prints the calculated distance between two points Console.WriteLine("The distance between point1 and point4 is: {0:0.00}", Points3DDistance.GetDistance3DPoints(point1, point4)); Path path = new Path(); //creates a new instance path of type (class) Path path.AddPoint(point1); //adds points to the path path.AddPoint(point2); path.AddPoint(point3); path.AddPoint(point4); PathStorage.WritePathToFile(path); //writes the path to a file using the method path.PrintPath(PathStorage.ReadPathFromFile()); //prints the read path from a file, so we can test what had been read }
static void Main() { var p1 = new Point3D(2, 1, 4); Console.WriteLine("Point 1: {0}", p1); Console.WriteLine("Point O: {0}", Point3D.O); Console.WriteLine(); Console.WriteLine("Distance between points 1 and O: {0}", Distance.GetDistance(p1, Point3D.O)); var path1 = new Path(p1, Point3D.O); Console.WriteLine(); Console.WriteLine("Path to save: {0}", path1); PathStorage.Save(path1, "MyPath"); Console.WriteLine(); Console.WriteLine("Loaded path: {0}", PathStorage.Load("MyPath")); }
public static Path PathLoad(string path) { Path loadPath = new Path(); using (StreamReader reader=new StreamReader(path)) { string line = reader.ReadLine(); while (line!=null) { string[] splited = line.Split(':'); string[] points = splited[1].Split(new char[]{',', '(',')',' '},StringSplitOptions.RemoveEmptyEntries); Point3D point = new Point3D(); point.X = int.Parse(points[0]); point.Y = int.Parse(points[1]); point.Z = int.Parse(points[2]); line = reader.ReadLine(); loadPath.AddPoint(point); } } Console.WriteLine("Path loaded!"); return loadPath; }
public void RemovePoint(Point3D point) { paths.Remove(point); }
public void AddPoint(Point3D point) { paths.Add(point); }
static Point3D() { origin = new Point3D(0, 0, 0); }
//method to add points in the list public void AddPoint(Point3D point3D) { pointSequence.Add(point3D); }
public void AddPoint(Point3D p) { this._points.Add(p); }
public static double CalcDistance(Point3D p1, Point3D p2) { return 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)); }
public static double CalculateDistanceBetweenTwoPoints(Point3D A, Point3D B) { double distance = Math.Sqrt(Math.Pow((A.X - B.X), 2) + Math.Pow((A.Y - B.Y), 2) + Math.Pow((A.Z - B.Z), 2)); return distance; }