示例#1
0
        /* TODO delete
         private static List<GridPolygonArea> getBlankPoligon(GridInfo gridInfo) {

                 var width = gridInfo.Width;
                 var height = gridInfo.Height;

                 gridInfo.MinX -= width * 0.2;
                 gridInfo.MaxX += width * 0.2;

                 gridInfo.MinY -= height * 0.2;
                 gridInfo.MaxY += height * 0.2;

                 var poligon = new GridPolygonArea {Type = GridPolygonAreaType.outerArea};

                 var points = new List<GridPoint>();

                 points.Add(new GridPoint(gridInfo.MinX, gridInfo.MinY));
                 points.Add(new GridPoint(gridInfo.MinX, gridInfo.MaxY));
                 points.Add(new GridPoint(gridInfo.MaxX, gridInfo.MaxY));
                 points.Add(new GridPoint(gridInfo.MaxX, gridInfo.MinY));

                 poligon.Points = points.ToArray();
                 return new List<GridPolygonArea> { poligon };
         }*/

        private static GridPoint[] getNearestPoints(GridPoint regPoint, GridPoint[] irregularPoints, double radius, int sectorsCount, int maxNumOfPointsInSector)
        {
            var points = new SimpleSortedList[sectorsCount];

            var sectorPointLength = sectorsCount - 1;

            for (int idx = 0; idx < sectorsCount; ++idx)
            {
                points[idx] = new SimpleSortedList(maxNumOfPointsInSector);
            }

            for (int idx = 0; idx < irregularPoints.Length; ++idx)
            {
                var irregularPoint = irregularPoints[idx];
                var distance = irregularPoint.distanceToPoint2D(regPoint);
                if (distance <= radius)
                {
                    var angle = 180 + Math.Atan2(irregularPoint.Y - regPoint.Y, irregularPoint.X - regPoint.X) * 180 / Math.PI;
                    if (angle >= 360)
                    {
                        points[sectorPointLength].add(irregularPoint, distance);
                        continue;
                    }
                    if (angle <= 0)
                    {
                        points[0].add(irregularPoint, distance);
                        continue;
                    }
                    var sect = (int)(angle / (360f / sectorsCount));
                    points[sect].add(irregularPoint, distance);
                }
            }

            var result = new List<GridPoint>();
            for (int idx = 0; idx < sectorsCount; ++idx)
            {
                result.AddRange(points[idx].toList());
            }

            return result.ToArray();
        }
示例#2
0
        /// <summary>
        /// Находится ли точка на отрезке
        /// </summary>
        /// <param name="segmentPoint1">точка начала отрезка</param>
        /// <param name="segmentPoint2">точка конца отрезка</param>
        /// <param name="point">интересующая точка</param>
        /// <returns>тру если находится</returns>
        private bool isPointInSegment(GridPoint segmentPoint1, GridPoint segmentPoint2, GridPoint point)
        {
            if (segmentPoint1.Equals(point))
            {
                return(true);
            }
            if (segmentPoint2.Equals(point))
            {
                return(true);
            }

            var a  = new GridPoint(segmentPoint2.X - segmentPoint1.X, segmentPoint2.Y - segmentPoint1.Y);
            var b  = new GridPoint(point.X - segmentPoint1.X, point.Y - segmentPoint1.Y);
            var sa = a.X * b.Y - b.X * a.Y;

            if (sa > 0 || sa < 0)
            {
                return(false);
            }

            if (a.X * b.X < 0 || a.Y * b.Y < 0)
            {
                return(false);
            }

            if (Math.Sqrt(a.X * a.X + a.Y * a.Y) < Math.Sqrt(b.X * b.X + b.Y * b.Y))
            {
                return(false);
            }

            return(true);
        }