Ejemplo n.º 1
0
        public static void CalculateDistance(Point3D p1, Point3D p2)
        {
            double deltaX = p2.PointX - p1.PointX;
            double deltaY = p2.PointY - p1.PointY;
            double deltaZ = p2.PointZ - p1.PointZ;

            double distance = (double)Math.Sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ);

            Console.WriteLine("The Distance between the 2 points is {0}", distance);
        }
Ejemplo n.º 2
0
        public static List<Point3D> ReadData()
        {
            List<Point3D> path = new List<Point3D>();
            string line;
            StreamReader sr = new StreamReader("../../Input.txt");

            try
            {
                string pattern = "(\\d+[\\.{1}\\d+]*).[^\\.\\d]*(\\d+[\\.{1}\\d+]*).[^\\.\\d]*(\\d+[\\.{1}\\d+]*)";
                line = sr.ReadLine();

                using (sr)
                {
                    while (line != null)
                    {
                        double x;
                        double y;
                        double z;

                        MatchCollection matches = Regex.Matches(line, pattern);
                        foreach (Match match in matches)
                        {
                            x = Double.Parse(match.Groups[1].Value);
                            y = Double.Parse(match.Groups[2].Value);
                            z = Double.Parse(match.Groups[3].Value);

                            Point3D point = new Point3D(x, y, z);
                            path.Add(point);
                        }

                        line = sr.ReadLine();
                    }
                }
            }

            catch(FileNotFoundException fnf)
            {
                Console.WriteLine("Input.txt not found!" + fnf.Message);
            }
            catch(FileLoadException fle)
            {
                Console.WriteLine("Problem loading Input.txt " + fle.Message);
            }

            finally
            {
                sr.Close();
            }

            return path;
        }