// Problem 2 Distance Calculator
 public static double DistanceBetween3DPointsCalculator(Point3D pointOne, Point3D pointTwo)
 {
     double distance = Math.Sqrt((
         (pointOne.PointX - pointTwo.PointX) * (pointOne.PointX - pointTwo.PointX)) +
         ((pointOne.PointY - pointTwo.PointY) * (pointOne.PointY - pointTwo.PointY)) +
         ((pointOne.PointZ - pointOne.PointZ) * (pointOne.PointZ - pointOne.PointZ)));
     return distance;
 }
Example #2
0
 static void Main()
 {
     Point3D pointOne = new Point3D(0, 0, 0);
     Point3D pointTwo = new Point3D(1, 2, 3);
     Console.WriteLine("PROBLEM ONE: ");
     Console.WriteLine("First point coordinates: ");
     Console.WriteLine(pointOne);
     Console.WriteLine("Second point coordinates: ");
     Console.WriteLine(pointTwo);
     Console.WriteLine("---------------------");
     Console.WriteLine("PROBLEM TWO: ");
     Console.WriteLine("Distance between the two points: ");
     double distance = DistanceCalculator.DistanceBetween3DPointsCalculator(pointOne, pointTwo);
     Console.WriteLine(distance);
 }
Example #3
0
        // This method fills the list in Path3D class with points from a text file.
        public static List<Point3D> PointExtraction(string path)
        {
            Regex regex = new Regex(@"(\d+),\s?(\d+),\s?(\d+)|[A-Za-z]:\s?(\d+)[^a-zA-Z]+?[a-zA-Z]:\s?(\d+)[^a-zA-Z]+?[a-zA-Z]:\s?(\d+)"); // regex for taking the points from a text file
            List<Euclidean3D.Point3D> points = new List<Point3D>();
            string file = File.ReadAllText(path);
            foreach (Match match in regex.Matches(file))
            {
                double pointX = new double();
                double pointY = new double();
                double pointZ = new double();

                try
                {

                    if (match.Groups[1].Value != string.Empty)
                    {
                        pointX = double.Parse(match.Groups[1].Value);
                        pointY = double.Parse(match.Groups[2].Value);
                        pointZ = double.Parse(match.Groups[3].Value);

                    }
                    else
                    {
                        pointX = double.Parse(match.Groups[4].Value);
                        pointY = double.Parse(match.Groups[5].Value);
                        pointZ = double.Parse(match.Groups[6].Value);

                    }
                    Euclidean3D.Point3D point = new Euclidean3D.Point3D(pointX, pointY, pointZ);
                    points.Add(point);
                }
                catch(FormatException ex)
                {
                    Console.Error.WriteLine(ex.Message);
                }

            }
            return points;
        }