找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 167|回复: 0

多段线

[复制链接]

0

主题

0

回帖

26

积分

管理员

积分
26
发表于 2024-3-6 11:49:11 | 显示全部楼层 |阅读模式
  1. AcDbObjectId FymPolyline::Add(const AcGePoint2dArray& points, double width, Adesk::Boolean isClosed)
  2. {
  3.         int numVerts = points.length();//计算输入点数组的长度
  4.         AcDbPolyline* pPline = new AcDbPolyline(numVerts);
  5.         for (int i = 0; i < points.length(); i++)
  6.         {
  7.                 pPline->addVertexAt(i, points.at(i), 0, width, width, 0); //将每个点添加到多段线中
  8.         }
  9.         pPline->setClosed(isClosed);//为真,则多线段将被设置为闭合
  10.         return FymDatabase::PostToModelSpace(pPline);
  11. }
  12. AcDbObjectId FymPolyline::Add(const AcGePoint2d& ptStart, const AcGePoint2d& ptEnd, double width)
  13. {
  14.         AcGePoint2dArray points;
  15.         points.append(ptStart);
  16.         points.append(ptEnd);
  17.         return Add(points, width);
  18. }
  19. //2d多段线
  20. AcDbObjectId FymPolyline::Add2dPolyline(const AcGePoint3dArray& points, double startWidth, double endWidth, Adesk::Boolean isClosed)
  21. {
  22.         AcGePoint3dArray verPoints = points;
  23.         AcDb2dPolyline* pPline = new AcDb2dPolyline(AcDb::k2dSimplePoly, verPoints, 0, isClosed, startWidth, endWidth);
  24.         return FymDatabase::PostToModelSpace(pPline);
  25. }
  26. //3d多段线
  27. AcDbObjectId FymPolyline::Add3dPolyline(const AcGePoint3dArray& points)
  28. {
  29.         AcGePoint3dArray verPts = points;
  30.         AcDb3dPolyline* pPline = new AcDb3dPolyline(AcDb::k3dSimplePoly, verPts);
  31.         return FymDatabase::PostToModelSpace(pPline);
  32. }
  33. //正多边形,(rotation)为旋转角度
  34. AcDbObjectId FymPolyline::Add3dPolyGon(const AcGePoint2d& ptCenter, int number, double radius, double rotation, double width)
  35. {
  36.         double angle = 2 * FymMathUtil::PI() / (double)number;//计算每个顶点与中心的夹角
  37.         AcGePoint2dArray points;//存储多段线的所有顶点
  38.         for (int i = 0; i < number; i++)
  39.         {
  40.                 AcGePoint2d pt;
  41.                 pt.x = ptCenter.x + radius * cos(i * angle);
  42.                 pt.y = ptCenter.y + radius * sin(i * angle);
  43.                 points.append(pt);
  44.         }
  45.         AcDbObjectId polyId = Add(points, width, Adesk::kTrue);
  46.         FymEditor::Rotate(polyId, ptCenter, rotation);
  47.         return polyId;
  48. }
  49. //对角线矩形
  50. AcDbObjectId FymPolyline::AddRectang(const AcGePoint2d& pt1, const AcGePoint2d& pt2, double width)
  51. {
  52.         double x1 = pt1.x, x2 = pt2.x;
  53.         double y1 = pt1.y, y2 = pt2.y;
  54.         AcGePoint2d ptLeftBottom(min(x1, x2), min(y1, y2));
  55.         AcGePoint2d ptRightBottom(max(x1, x2), min(y1, y2));
  56.         AcGePoint2d ptRightTop(max(x1, x2), max(y1, y2));
  57.         AcGePoint2d ptLeftTop(min(x1, x2), max(y1, y2));
  58.         AcGePoint2dArray points;
  59.         points.append(ptLeftBottom);
  60.         points.append(ptRightBottom);
  61.         points.append(ptRightTop);
  62.         points.append(ptLeftTop);
  63.         return Add(points, width, Adesk::kTrue);
  64. }
  65. //测试:小爱心,bulge0.5为四分之一圆
  66. AcDbObjectId FymPolyline::AddPolyCircle(const AcGePoint2d& ptCenter, double radius, double width)
  67. {
  68.         AcGePoint2d pt1, pt2, pt3, pt4;
  69.         pt1.x = ptCenter.x + radius;
  70.         pt1.y = ptCenter.y;
  71.         pt2.x = ptCenter.x - radius;
  72.         pt2.y = ptCenter.y;
  73.         pt3.x = ptCenter.x ;
  74.         pt3.y = ptCenter.y + radius;
  75.         pt4.x = ptCenter.x;
  76.         pt4.y = ptCenter.y - radius;
  77.         AcDbPolyline* pPloy = new AcDbPolyline(4);
  78.         pPloy->addVertexAt(0, pt1, 1, width, width);
  79.         pPloy->addVertexAt(1, pt3, 1, width, width);
  80.         pPloy->addVertexAt(2, pt2, 0.1, width, width);
  81.         pPloy->addVertexAt(3, pt4, 0.1, width, width);
  82.         pPloy->setClosed(Adesk::kTrue);
  83.         return FymDatabase::PostToModelSpace(pPloy);
  84. }
  85. AcDbObjectId FymPolyline::SetWidth(const AcDbObjectId& polyId, ads采用real width)
  86. {
  87.         AcDbPolyline* pPline = NULL;
  88.         if (acdbOpenObject(pPline,polyId,AcDb::kForWrite)==Acad::eOk)
  89.         {
  90.                 pPline->setConstantWidth(width);
  91.                 pPline->close();
  92.         }
  93.         return FymDatabase::PostToModelSpace(pPline);
  94. }
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|膜结构网

GMT+8, 2024-12-28 13:32 , Processed in 0.151609 second(s), 23 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表