Exemplo n.º 1
0
        public static int AngleNum(this Polygon2d polygon2d, double tarAngle = 90)
        {
            int angleCount = 0;

            for (int i = 0; i < polygon2d.VertexCount; i++)
            {
                if (polygon2d.OpeningAngleDeg(i).EqualPrecision(tarAngle))
                {
                    angleCount += 1;
                }
            }
            return(angleCount);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 删除多边形的尖角 删除共线的点
        /// </summary>
        /// <returns></returns>
        public static Polygon2d RemoveSharpCcorners(this Polygon2d polygon2d, double AnglePRECISION = 1.0)
        {
            List <Vector2d> vector2ds = new List <Vector2d>();

            for (int i = 0; i < polygon2d.VertexCount; i++)
            {
                double openingAngle = polygon2d.OpeningAngleDeg(i);

                if (openingAngle >= AnglePRECISION && openingAngle <= 180 - AnglePRECISION)
                {
                    vector2ds.Add(polygon2d[i]);
                }
            }

            return(new Polygon2d(vector2ds));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 线圈是否为矩形
        /// </summary>
        /// <returns></returns>
        public static bool IsRectangle(this Polygon2d polygon2d)
        {
            int count = polygon2d.VertexCount;

            if (count != 4)
            {
                return(false);
            }
            for (int i = 0; i < polygon2d.VertexCount; i++)
            {
                if (!polygon2d.OpeningAngleDeg(i).EqualPrecision(90))
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 线圈是否为直角梯形
        /// </summary>
        /// <returns></returns>
        public static bool IsTrapezoid_RightAngle(this Polygon2d polygon2d)
        {
            int count = polygon2d.VertexCount;

            if (count != 4)
            {
                return(false);
            }
            int calAngleCounr = 0;

            for (int i = 0; i < polygon2d.VertexCount; i++)
            {
                if (polygon2d.OpeningAngleDeg(i).EqualPrecision(90))
                {
                    calAngleCounr += 1;
                }
            }
            if (calAngleCounr != 2)
            {
                return(false);
            }
            IEnumerable <Segment2d> segment2ds = polygon2d.SegmentItr();
            int segmntCount = segment2ds.Count();

            for (int i = 0; i < segmntCount; i++)
            {
                for (int j = 0; j < segmntCount; j++)
                {
                    if (i <= j)
                    {
                        continue;
                    }
                    Segment2d segment2d01 = segment2ds.ElementAt(i);
                    Segment2d segment2d02 = segment2ds.ElementAt(j);
                    if (segment2d01.Direction.Dot(segment2d02.Direction).EqualPrecision(-1))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 线圈是否为三角形
        /// </summary>
        /// <param name="polygon2d"></param>
        /// <returns></returns>
        public static bool IsTriangle(this Polygon2d polygon2d)
        {
            int count = polygon2d.VertexCount;

            if (count != 3)
            {
                return(false);
            }
            double angle = 0;

            for (int i = 0; i < polygon2d.VertexCount; i++)
            {
                angle += polygon2d.OpeningAngleDeg(i);
            }
            if (angle.EqualPrecision(180))
            {
                return(true);
            }
            return(false);
        }