获得平行四边形中,那条较长的中心线

 /// <summary>
        /// 创建平行四边形中,较长的一条中心线
        /// </summary>
        public IGeometry CreateLine(IPolygon pPolygon)
        {
            if (pPolygon == null)
            {
                return null;
            }

            try
            {
                 首先判断pPolygon是否为平行四边形
                if (!IsParallelogram(pPolygon))
                {
                    return null;
                }

                IPointCollection pPointCol = pPolygon as IPointCollection;

                IPoint pFstPt = null;
                IPoint pSecPt = null;
                IPoint pTrdPt = null;
                IPoint pForPt = null;
                 这些点事按照绘制顺序来存储的
                pFstPt = pPointCol.get_Point(0);
                pSecPt = pPointCol.get_Point(1);
                pTrdPt = pPointCol.get_Point(2);
                pForPt = pPointCol.get_Point(3);

                IPoint pFst = new PointClass();
                IPoint pSec = new PointClass();
                IPoint pTrd = new PointClass();
                IPoint pFor = new PointClass();
                 获得线段中点
                pFst.PutCoords((pFstPt.X + pSecPt.X) / 2, (pFstPt.Y + pSecPt.Y) / 2);
                pSec.PutCoords((pSecPt.X + pTrdPt.X) / 2, (pSecPt.Y + pTrdPt.Y) / 2);
                pTrd.PutCoords((pTrdPt.X + pForPt.X) / 2, (pTrdPt.Y + pForPt.Y) / 2);
                pFor.PutCoords((pForPt.X + pFstPt.X) / 2, (pForPt.Y + pFstPt.Y) / 2);

                object oBefore = Type.Missing;
                object oAfter = Type.Missing;
                ILine pLineLR = new LineClass();
                pLineLR.PutCoords(pFst, pTrd);
                ILine pLineUL = new LineClass();
                pLineUL.PutCoords(pSec, pFor);

                IPolyline pPolylineLR = new PolylineClass();
                IPolyline pPolylineUL = new PolylineClass();
                 转成IPolyline
                (pPolylineLR as ISegmentCollection).AddSegment(pLineLR as ISegment, ref oBefore, ref oAfter);
                (pPolylineUL as ISegmentCollection).AddSegment(pLineUL as ISegment, ref oBefore, ref oAfter);
                (pPolylineLR as ITopologicalOperator).Simplify();
                (pPolylineUL as ITopologicalOperator).Simplify();

                IGeometry pGeoLine;

                 得到较长的一条中心线
                if (pPolylineLR.Length > pPolylineUL.Length)
                {
                    pGeoLine = pPolylineLR as IGeometry;
                }
                else
                {
                    pGeoLine = pPolylineUL as IGeometry;
                }

                return pGeoLine;
            }
            catch (Exception ex)
            {
                return null;
            }
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值