判断多边形是否为平行四边形

深藏阁楼爱情的钟 2022-08-07 01:33 345阅读 0赞
  1. /// <summary>
  2. /// 判断多边形是否为平行四边形
  3. /// </summary>
  4. /// <param name="pPolygon">多边形</param>
  5. /// <returns></returns>
  6. public bool IsParallelogram(IPolygon pPolygon)
  7. {
  8. bool bResult = false;
  9. if (pPolygon == null)
  10. {
  11. return false;
  12. }
  13. try
  14. {
  15. IPointCollection pPointCol = pPolygon as IPointCollection;
  16. 这里判断5个点,是因为AE中绘制多边形是从起点开始,再绘制到起点结束,为一个封闭的图形
  17. if (pPointCol.PointCount != 5)
  18. {
  19. return false;
  20. }
  21. IPoint pFstPt = null;
  22. IPoint pSecPt = null;
  23. IPoint pTrdPt = null;
  24. IPoint pForPt = null;
  25. 这些点是按照绘制顺序来存储的
  26. pFstPt = pPointCol.get_Point(0);
  27. pSecPt = pPointCol.get_Point(1);
  28. pTrdPt = pPointCol.get_Point(2);
  29. pForPt = pPointCol.get_Point(3);
  30. ILine pFstLine = new LineClass();
  31. ILine pSecLine = new LineClass();
  32. ILine pTrdLine = new LineClass();
  33. ILine pForLine = new LineClass();
  34. 获得四边形的四条边
  35. pFstLine.PutCoords(pFstPt, pSecPt);
  36. pSecLine.PutCoords(pSecPt, pTrdPt);
  37. pTrdLine.PutCoords(pTrdPt, pForPt);
  38. pForLine.PutCoords(pForPt, pFstPt);
  39. 对边相等则是平行四边形
  40. if (pFstLine.Length == pTrdLine.Length && pSecLine.Length == pForLine.Length)
  41. {
  42. bResult = true;
  43. }
  44. }
  45. catch (Exception ex)
  46. {
  47. bResult = false;
  48. }
  49. return bResult;
  50. }

发表评论

表情:
评论列表 (有 0 条评论,345人围观)

还没有评论,来说两句吧...

相关阅读