Esempio n. 1
0
        public static Point2dCollection SortPoint2D(Point2dCollection point2Ds)
        {
            var raw = point2Ds.ToArray();

            Array.Sort(raw, new Sort2DbyX());
            return(new Point2dCollection(raw));
        }
Esempio n. 2
0
        public static bool WN_Algorithm(Point2dCollection b, Point2dCollection t)
        {
            var ba = b.ToArray();

            foreach (Point2d p in t)
            {
                if (WNumAlgorithm.wn_PnPoly(p, ba, b.Count) != 0)
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 3
0
        public static bool wn_PointInPolyline(Point2dCollection points, Point2dCollection tests)
        {
            try
            {
                var boundarypoints = points.ToArray();
                var num            = points.Count;

                foreach (Point2d tpoint in tests)
                {
                    if (WNumAlgorithm.wn_PnPoly(tpoint, boundarypoints, num) != 0)
                    {
                        return(true);
                    }
                }
            }
            catch (System.Exception)
            {
            }
            return(false);
        }
Esempio n. 4
0
        //internal static void DouglasPeuckerReduction(Point2dCollection points, Point2d firstPoint, Point2d lastPoint,
        //    Double toleranceSquared, ref List<Point2d> pointIndexsToKeep)
        //{
        //    float maxDistanceSquared = 0, tmp = 0, areaSquared = 0;
        //    double X = 0;
        //    float Y = 0, bottomSquared = 0, distanceSquared = 0;
        //    int indexFarthest = 0;

        //    unsafe
        //    {
        //        foreach (var point in points)
        //            {
        //                //Perpendicular distance
        //                tmp = 0.5f*
        //                      ((lastPoint.Y - i)*(firstPoint - i) +
        //                       (*(samples + lastPoint) - *(samples + i))*(*(samples + firstPoint) - *(samples + i)));
        //                //Abs
        //                areaSquared = tmp*tmp;
        //                X = (firstPoint.X - lastPoint.X);
        //                Y = (*(samples + firstPoint) - *(samples + lastPoint));
        //                bottomSquared = X*X + Y*Y;
        //                distanceSquared = areaSquared/bottomSquared;

        //                if (distanceSquared > maxDistanceSquared)
        //                {
        //                    maxDistanceSquared = distanceSquared;
        //                    indexFarthest = i;
        //                }
        //            }
        //    }

        //    if (maxDistanceSquared > toleranceSquared && indexFarthest != 0)
        //    {
        //        //Add the largest point that exceeds the tolerance
        //        DouglasPeuckerReduction(points, firstPoint, indexFarthest, toleranceSquared, ref pointIndexsToKeep);
        //        pointIndexsToKeep.Add(indexFarthest);
        //        DouglasPeuckerReduction(points, indexFarthest, lastPoint, toleranceSquared, ref pointIndexsToKeep);
        //    }
        //}


        /// <summary>
        /// Douglases the peucker reduction.
        /// </summary>
        /// <param name="Points">The points.</param>
        /// <param name="Tolerance">The tolerance.</param>
        /// <returns>Point2d[].</returns>
        public static Point2d[] DouglasPeuckerReduction
            (List <Point2d> Points, Double Tolerance)
        {
            if (Points == null || Points.Count < 3)
            {
                return(Points.ToArray());
            }

            Point2d        firstPoint        = Points.First();
            Point2d        lastPoint         = Points.Last();
            List <Point2d> pointIndexsToKeep = new List <Point2d>();

            //Add the first and last index to the keepers
            pointIndexsToKeep.Add(firstPoint);
            pointIndexsToKeep.Add(lastPoint);

            int i = 1;

            while (Equals(firstPoint, lastPoint))
            {
                lastPoint = Points[Points.Count - i++];
            }

            //The first and the last point cannot be the same
            if (!(Equals(firstPoint, lastPoint)))
            {
                DouglasPeuckerReduction(Points.ToArray(), firstPoint, lastPoint,
                                        Tolerance, ref pointIndexsToKeep);

                Point2dCollection returnPoints = new Point2dCollection();
                //pointIndexsToKeep.Sort();
                foreach (var point in pointIndexsToKeep)
                {
                    returnPoints.Add(point);
                }

                return(returnPoints.ToArray());
            }
            return(Points.ToArray());
        }
Esempio n. 5
0
        private static IList <Point3dCollection> IncludeIntersectingNeighbor(Point3dCollection p3D, ACADDB.ObjectIdCollection originalCollection)
        {
            IList <Point3dCollection> outCollection        = new List <Point3dCollection>();
            Point3dCollection         temPoint3DCollection = null;

            foreach (ACADDB.ObjectId polyoid in originalCollection)
            {
                var index = originalCollection.IndexOf(polyoid);
                Point2dCollection polypoints = PGA.AcadUtilities.AcadUtilities.GetPointsFromPolyline(polyoid);
                Point2d           nearPoint  = new Point2d();
                Point2d           outPoint   = new Point2d();
                var pointindex = 0;
                temPoint3DCollection = new Point3dCollection();
                Point2dCollection p2d = PGA.AcadUtilities.AcadUtilities.ConvertTo2d(p3D);
                foreach (var point in polypoints)
                {
                    if (PGA.AcadUtilities.PolygonFunctions.IsPointInsidePolygon(point, p2d.ToArray(), true))
                    {
                        double maxdist       = 100000;
                        double mindist       = 0;
                        var    matchingIndex = -1;
                        //Points on Poly are not Lidar Points Must add manually
                        for (int i = 0; i < p2d.Count - 1; i++)
                        {
                            mindist = PGA.AcadUtilities.PolygonFunctions.DistanceToSegment(point, p2d[i], p2d[i + 1], ref nearPoint);
                            if (mindist < maxdist)
                            {
                                maxdist    = mindist;
                                outPoint   = nearPoint;
                                pointindex = i;
                            }
                        }
                        //for (int i = 0; i < p3D.Count; i++)
                        //{
                        //    if (Equals(p3D[i], outPoint))
                        //        temPoint3DCollection.Add(p3D[i]);
                        //}
                        if (maxdist < 5.0)
                        {
                            temPoint3DCollection.Add(new Point3d(point.X, point.Y, p3D[pointindex].Z));
                        }
                        // temPoint3DCollection.Add(p3D[pointindex]);
                        //var matchingIndex = p2d.IndexOf(outPoint);
                        //if (matchingIndex != -1)
                        //  temPoint3DCollection.Add(p3D[index][matchingIndex]);
                    }
                }
                if (temPoint3DCollection != null)
                {
                    outCollection.Add(temPoint3DCollection);
                }
            }

            return(outCollection);
        }