Example #1
0
        private PlaceOfInterest FindPivot(List <PlaceOfInterest> points)
        {
            PlaceOfInterest lowestLeftPoint = points[0];

            for (int i = 1; i < points.Count; i++)
            {
                if (points[i].LongitudeX == lowestLeftPoint.LongitudeX)
                {
                    if (points[i].LatitudeY < lowestLeftPoint.LatitudeY)
                    {
                        lowestLeftPoint = points[i];
                    }
                }
                else if (points[i].LongitudeX < lowestLeftPoint.LongitudeX)
                {
                    lowestLeftPoint = points[i];
                }
            }

            //return _points.First(c => c.Y == _points.Max(x => x.Y));

            return(lowestLeftPoint);
        }
Example #2
0
        private List <PlaceOfInterest> ConvexHull(PlaceOfInterest pivot, List <PlaceOfInterest> points)
        {
            List <PlaceOfInterest> Hull = new List <PlaceOfInterest>();

            points.Remove(pivot);
            var s = new RadioSort(pivot);

            points.Sort(s);
            Hull.Add(pivot);     // first point
            Hull.Add(points[0]); // second point
            points.RemoveAt(0);
            Hull.Add(points[0]); // third point
            points.RemoveAt(0);
            while (points.Count != 0)
            {
                long value = s.SignedArea(Hull[Hull.Count - 2], Hull[Hull.Count - 1], points[0]);
                if (value < 0)
                {
                    Hull.Add(points[0]);
                    points.RemoveAt(0);
                }
                else if (value == 0)
                {
                    Hull.RemoveAt(Hull.Count - 1);
                    Hull.Add(points[0]);
                    points.RemoveAt(0);
                }
                else
                {
                    Hull.RemoveAt(Hull.Count - 1);
                    //Hull.Add(points[0]);
                    // points.RemoveAt(0);
                }
            }
            return(Hull);
        }