Exemplo n.º 1
0
        public static ClosestTwoPointsAndDistance FindClosestTwoPoints(Point[] points)
        {
            ClosestTwoPointsAndDistance closestTwoAndDistance = new ClosestTwoPointsAndDistance();
            double minimalDistance = double.MaxValue;

            for (int first = 0; first < points.Length; first++)
            {
                for (int second = first + 1; second < points.Length; second++)
                {
                    Point  p1 = points[first];
                    Point  p2 = points[second];
                    double currentDistance = CalcDistance(p1, p2);

                    if (currentDistance < minimalDistance)
                    {
                        minimalDistance       = currentDistance;
                        closestTwoAndDistance = new ClosestTwoPointsAndDistance()
                        {
                            First    = p1,
                            Second   = p2,
                            Distance = currentDistance
                        };
                    }
                }
            }

            return(closestTwoAndDistance);
        }
Exemplo n.º 2
0
        private static void Main()
        {
            Point[] points = ReadArrayOfPoints();

            ClosestTwoPointsAndDistance closestTwoPointsAndDistance = FindClosestTwoPoints(points);

            Console.WriteLine($"{closestTwoPointsAndDistance.Distance:F3}");
            Console.WriteLine(closestTwoPointsAndDistance.First);
            Console.WriteLine(closestTwoPointsAndDistance.Second);
        }