Exemplo n.º 1
0
Arquivo: Calc.cs Projeto: desi4ok/OOP
 public static double DistanceCalculator(Point3D firstPoint, Point3D secondPoint)
 {
     double distance = Math.Sqrt(Math.Pow(secondPoint.PointX - firstPoint.PointX, 2) +
         Math.Pow(secondPoint.PointY - firstPoint.PointY, 2) +
         Math.Pow(secondPoint.PointZ - firstPoint.PointZ, 2));
     return distance;
 }
Exemplo n.º 2
0
        public static Path3D ReadData()
        {
            Path3D paths = new Path3D();
            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 pointX;
                        double pointY;
                        double pointZ;

                        MatchCollection matches = Regex.Matches(line, pattern);
                        foreach (Match match in matches)
                        {
                            pointX = double.Parse(match.Groups[1].Value);
                            pointY = double.Parse(match.Groups[2].Value);
                            pointZ = double.Parse(match.Groups[3].Value);

                            Point3D point = new Point3D(pointX, pointY, pointZ);
                            paths.AddPoint(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 paths;
        }
Exemplo n.º 3
0
 static void Main()
 {
     Point3D point = new Point3D(5, 5, 5);
     Console.WriteLine(point);
     Console.WriteLine(Point3D.StartingPoint);
 }
Exemplo n.º 4
0
 public void AddPoint(Point3D point)
 {
     this.points.Add(point);
 }
Exemplo n.º 5
0
 static void Main()
 {
     Point3D firstPoint = new Point3D(-7, -4, 3);
     Point3D secondPoint = new Point3D(17, 6, 2.5);
     Console.WriteLine(Calc.DistanceCalculator(firstPoint, secondPoint));
 }