/// <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;
}
}
获得平行四边形中,那条较长的中心线
最新推荐文章于 2020-04-11 15:20:45 发布