/// <summary>
 /// Calculates distance between two points in 3D space using <see cref="Point3D"/> type coordinates.
 /// </summary>
 /// <param name="pointA">Point A coordinates.</param>
 /// <param name="pointB">Point B coordinates</param>
 /// <returns></returns>
 public static double Distance(Point3D pointA, Point3D pointB)
 {
     double axisXDistance = pointA.X - pointB.X;
     double axisYDistance = pointA.Y - pointB.Y;
     double axisZDistance = pointA.Z - pointB.Z;
     return Math.Sqrt((axisXDistance * axisXDistance) + (axisYDistance * axisYDistance) + (axisZDistance * axisZDistance));
 }
        static void Main()
        {
            Point3D point = new Point3D(1, 2, 3);

            Console.WriteLine(point);
            Console.WriteLine(Point3D.Origin);

            var dist = Point3DExtensions.CalculateDistance(point, Point3D.Origin);
            Console.WriteLine(dist);

            var path = new Path();
            for (int i = 0; i < 10; i++)
            {
                path.AddPoint(new Point3D() { X = i, Y = i * 2, Z = i + 3 });
            }

            string pathStr = "../../path.txt";
            PathStorage.SavePath(path, pathStr);
            var pathFromFile = PathStorage.LoadPath(pathStr);

            foreach (var p in pathFromFile)
            {
                Console.WriteLine(p);
            }
        }
 public static double CalculateDistanceBetweenTwoPoints(Point3D firstPoint, Point3D secondPoint)
 {
     double coordXDistance = firstPoint.CoordX - secondPoint.CoordX;
     double coordYDistance = firstPoint.CoordY - secondPoint.CoordY;
     double coordZDistance = firstPoint.CoordZ - secondPoint.CoordZ;
     double euclidianDistance = Math.Sqrt(Math.Pow(coordXDistance, 2) + Math.Pow(coordYDistance, 2) + Math.Pow(coordZDistance, 2));
     return euclidianDistance;
 }
Beispiel #4
0
        public static void Main()
        {
            var center = Point3D.StartingPoint;
            Console.WriteLine("Ceneter coordinates: {0}", center);

            var pointA = new Point3D(10, 20, 30);
            Console.WriteLine("PointA coordinates: {0}", pointA);

            Console.ReadKey();
        }
Beispiel #5
0
 public static void Main()
 {
     var pointA = new Point3D(2, 4, 6);
     var pointB = new Point3D(10, 20, 30);
     Console.WriteLine("Distance between:");
     Console.WriteLine(" - pointA ({0})", pointA.ToString());
     Console.WriteLine(" - pointB ({0})", pointB.ToString());
     Console.WriteLine("is: {0}", DistanceCalculator.Distance(pointA, pointB));
     Console.ReadKey();
 }
Beispiel #6
0
 private static Point3D ConvertStringToPoint3D(string pointAsString)
 {
     char[] charsToRemove = { '(', ',', ' ', ')' };
     string[] pointCoord = pointAsString.Trim().Split(charsToRemove, StringSplitOptions.RemoveEmptyEntries);
     double coordX = Convert.ToDouble(pointCoord[0]);
     double coordY = Convert.ToDouble(pointCoord[1]);
     double coordZ = Convert.ToDouble(pointCoord[2]);
     //Console.WriteLine("[{0}, {1}, {2}]", coordX, coordY, coordZ);
     Point3D point = new Point3D(coordX, coordY, coordZ);
     return point;
 }
Beispiel #7
0
        /// <summary>
        /// Loads the 3D-points located in the text file to a list of points in 3Dspace. 
        /// </summary>
        /// <returns>Returns an <param name="Path"/> list of Point3D objects, representing points in space.</returns>
        public static Path3D Load(string file = null)
        {
            string currentPath = path;
            if (!string.IsNullOrWhiteSpace(file))
            {
                currentPath = file;
            }

            // instantiates the List to be returned
            var listCoordinates = new Path3D();
            using (var reader = new StreamReader(currentPath, Encoding.UTF8))
            {
                while (reader.Peek() > -1)
                {
                    // declate object to hold coordinates {x,y,z}
                    var point = new Point3D();
                    try
                    {
                        var line = reader.ReadLine();
                        if (line == null)
                        {
                            continue;
                        }

                        string[] lineWithCoordinates = line.Trim().Split((char)9);

                        // convert each component of 3D-coordinate to daouble and add it to the List of 3-D coordinates
                        point.X = double.Parse(lineWithCoordinates[0]);
                        point.Y = double.Parse(lineWithCoordinates[1]);
                        point.Z = double.Parse(lineWithCoordinates[2]);
                        listCoordinates.Add(point);
                    }
                    catch
                    {
                        // handling exception if some of the coordinates are not numbers
                        throw new ArgumentOutOfRangeException("Coordinates", "There are values which are not valid coordinates in the text file!.");
                    }
                }
            }

            return listCoordinates;
        }
Beispiel #8
0
        public static void Main()
        {
            Point3D firstPoint = new Point3D(1.1, 2.2, 3.3);
            Point3D secondPoint = new Point3D(3.3, 2.2, 1.1);

            double dist = DistanceCalculator.CalculateDistanceBetweenTwoPoints(firstPoint, secondPoint);
            Console.WriteLine("The distance between points ({0}) and ({1}) is {2:F2}.", firstPoint, secondPoint, dist);

            Path firstPath = new Path();
            firstPath.AddPointToPath(firstPoint);
            firstPath.AddPointToPath(secondPoint);
            Console.WriteLine(firstPath);

            PathStorage.SavePathToFile(firstPath, "FirstPath.txt");

            Path secondPath = PathStorage.LoadPathFromFile("Points.txt");
            Console.WriteLine(secondPath);

            PathStorage.SavePathToFile(secondPath, "NewPoints.txt");
        }
        public static void Main()
        {
            Point3D firstPoint = new Point3D(12.3, 4.7, 7.12);
            Console.WriteLine(firstPoint.ToString());
            Console.WriteLine(new string('=', 30));
            Point3D secondPoint = new Point3D(7.12, 12.3, 4.7);
            Console.WriteLine(secondPoint.ToString());
            Console.WriteLine(new string('=', 30));
            Console.WriteLine(DistanceCalc.Distance(firstPoint, secondPoint));
            Console.WriteLine(new string('=', 30));

            Path anyPath = new Path();
            anyPath.AddPoint(firstPoint);
            anyPath.AddPoint(secondPoint);

            PathStorage.SavePath(anyPath);

            Path loadedPath = new Path();
            PathStorage.LoadPath(loadedPath);
            for (int i = 0; i < loadedPath.ListOfPoints.Count; i++)
            {
                Console.WriteLine(loadedPath.ListOfPoints[i].ToString());
            }
        }
 public static double Distance(Point3D firstPoint, Point3D secondPoint)
 {
     return Math.Sqrt(Math.Pow(firstPoint.X - secondPoint.X, 2) + Math.Pow(firstPoint.Y - secondPoint.Y, 2) + Math.Pow(firstPoint.Z - secondPoint.Z, 2));
 }
Beispiel #11
0
 public void RemovePointFromPath(Point3D point)
 {
     this.PointPath.Remove(point);
 }
Beispiel #12
0
 public void AddPointToPath(Point3D point)
 {
     this.PointPath.Add(point);
 }
Beispiel #13
0
 static Point3D()
 {
     startPoint = new Point3D(0, 0, 0);
 }
 public void RemovePoint(Point3D point)
 {
     this.list.Remove(point);
 }
 ////Methods
 public void AddPoint(Point3D point)
 {
     this.list.Add(point);
 }