Beispiel #1
0
        public static Path3D ReadPathsFromFile(String filePath, Path3D path)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException("File Path can't be null. Can't read file");
            }

            if (path == null)
            {
                throw new ArgumentNullException("Path Object can't be null.");
            }

            FileStream file = File.Open(filePath, FileMode.Open, FileAccess.Read);

            String pattern = @"([0-9]([,\s]+)[0-9]([,\s]+)[0-9])";
            Regex rex = new Regex(pattern);
            Match match = rex.Match(File.ReadAllText(filePath));

            while (match.Success)
            {
                String res = match.Value;
                res = Regex.Replace(res, ",", String.Empty);
                int[] arr = res.Split(' ').Select(int.Parse).ToArray();

                Point3D point = new Point3D(arr);

                path.AddPoint(point);

                match = match.NextMatch();
            }

            return path;
        }
Beispiel #2
0
        public void AddPoint(Point3D point)
        {
            if (point == null)
            {
                throw new ArgumentNullException("Point can't be null");
            }

            this._pointsList.Add(point);
        }
        static void Main(string[] args)
        {
            Point3D pointA = new Point3D(new int[] { 1, 3, 5 });
            Point3D pointB = new Point3D(new int[] { 2, 4, 6 });

            double distance = DistanceCalculator.CalculateDistance(pointA, pointB);

            Console.WriteLine(distance);
        }
        public static double CalculateDistance(Point3D pointA, Point3D pointB)
        {
            double distance = Math.Sqrt(
                    Math.Pow(pointA.CurrentPosition[0] - pointB.CurrentPosition[0], 2)
                    +
                    Math.Pow(pointA.CurrentPosition[1] - pointB.CurrentPosition[1], 2)
                    +
                    Math.Pow(pointA.CurrentPosition[2] - pointB.CurrentPosition[2], 2)
                );

            return distance;
        }