天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 67|回复: 1

面域转多段线边界

[复制链接]
  • TA的每日心情
    开心
    3 天前
  • 签到天数: 49 天

    [LV.5]常住居民I

    185

    主题

    150

    回帖

    1695

    积分

    管理员

    积分
    1695
    发表于 2024-3-28 17:23:36 | 显示全部楼层 |阅读模式
    1. struct PlineSegment {
    2.         AcGePoint2d p1, p2;
    3.         double bulge=0.0;
    4.         int   reversed=0; // 0 unknown, -1 reversed, 1 not reversed
    5. };

    6. void cmdRegion2Pline()
    7. {
    8.         ads_point    pt;
    9.         ads_name     ent;
    10.         AcDbObjectId idRegion;

    11.         if (acedEntSel(_T("\nSelect region"), ent, pt) != RTNORM)
    12.                 return;

    13.         if (acdbGetObjectId(idRegion, ent) != Acad::eOk)
    14.                 return;

    15.         Acad::ErrorStatus es;
    16.         AcDbVoidPtrArray curves;
    17.         AcDbRegion *region;
    18.         AcGePlane regionPlane;
    19.         if ((es = acdbOpenObject(region, idRegion, AcDb::kForRead)) == Acad::eOk)
    20.         {
    21.                 region->getPlane(regionPlane);
    22.                 region->explode(curves);
    23.                 region->close();
    24.         }

    25.         AcGePoint3d origin;
    26.         AcGeVector3d axis1, axis2, norm(regionPlane.normal());
    27.         regionPlane.getCoordSystem(origin, axis1, axis2);
    28.         // Recalculate origin to be the closest point on the plane
    29.         double dp = origin.asVector().dotProduct(norm);
    30.         origin = AcGePoint3d::kOrigin + dp * norm;

    31.         AcGeMatrix3d mat_WCS_ECS, mat_ECS_WCS;
    32.         mat_WCS_ECS.setCoordSystem(origin, axis1, axis2, norm);
    33.         mat_ECS_WCS = mat_WCS_ECS.inverse();

    34.         int i, j, N=curves.length();
    35.         AcDbObject *obj;
    36.         AcDbCurve *crv;
    37.         AcDbArc *arc;
    38.         AcGePoint3d ps, pe;
    39.         double angle=0.0;
    40.         std::vector<PlineSegment> segments;
    41.         PlineSegment segment;
    42.         // Collect segment data:
    43.         for (i=0; i<N; ++i)
    44.         {
    45.                 obj = (AcDbObject*)curves[i];
    46.                 if (crv = AcDbCurve::cast(obj))
    47.                 {                       
    48.                         crv->getStartPoint(ps);
    49.                         crv->getEndPoint(pe);
    50.                         // Transform to ECS. After this z-components should be 0
    51.                         ps.transformBy(mat_ECS_WCS);
    52.                         pe.transformBy(mat_ECS_WCS);
    53.                         segment.p1 = AcGePoint2d(ps.x, ps.y);
    54.                         segment.p2 = AcGePoint2d(pe.x, pe.y);
    55.                         if (arc = AcDbArc::cast(obj))
    56.                                 segment.bulge = tan(0.25 * arc->totalAngle());
    57.                         else
    58.                                 segment.bulge = 0.0;
    59.                         segments.push_back(segment);
    60.                 }
    61.                 delete obj;
    62.         }
    63.         // When we stitch the polyline together we must make sure that start- and endpoints match.
    64.         AcDbDatabase *pDB = acdbHostApplicationServices()->workingDatabase();
    65.         AcDbPolyline* pline = new AcDbPolyline();
    66.         pline->setDatabaseDefaults(pDB);
    67.         unsigned int ix = 0;

    68.         for (i = 0; i < N; ++i)        {
    69.                 j = (i>0)? i-1 : N-1;
    70.                 PlineSegment &ps = segments[i];
    71.                 PlineSegment& psPrev = segments[j];
    72.                 if (psPrev.p2 == ps.p1)        {
    73.                         psPrev.reversed = ps.reversed = 1;
    74.                         pline->addVertexAt(ix++, ps.p1, ps.reversed * ps.bulge);
    75.                 } else if (psPrev.p1 == ps.p1){
    76.                         ps.reversed     = 1;
    77.                         psPrev.reversed = -1;
    78.                         pline->addVertexAt(ix++, ps.p1, ps.reversed * ps.bulge);
    79.                 } else if (psPrev.p2 == ps.p2) {
    80.                         ps.reversed     = -1;
    81.                         psPrev.reversed = 1;
    82.                         pline->addVertexAt(ix++, ps.p2, ps.reversed * ps.bulge);
    83.                 } else if (psPrev.p1 == ps.p2) {
    84.                         psPrev.reversed = ps.reversed = -1;
    85.                         pline->addVertexAt(ix++, ps.p2, ps.reversed * ps.bulge);
    86.                 }
    87.         }
    88.         pline->setClosed(true);
    89.         pline->transformBy(mat_WCS_ECS);
    90.         PostToDb(pDB, pline);
    91. }
    复制代码

     

     

     

     

    面域转多段线边界
    哎...膜结构车棚,签到来了1...
  • TA的每日心情
    开心
    3 天前
  • 签到天数: 49 天

    [LV.5]常住居民I

    185

    主题

    150

    回帖

    1695

    积分

    管理员

    积分
    1695
     楼主| 发表于 2024-3-29 09:02:46 | 显示全部楼层
    1. // Assume pRegion is a pointer to your AcDbRegion object
    2. AcDbVoidPtrArray curveSegments;
    3. pRegion->explode(curveSegments); // Explode the region into constituent curves

    4. // Create a new polyline
    5. AcDbPolyline* pPolyline = new AcDbPolyline();

    6. // Iterate through the curve segments and add them to the polyline
    7. for (int i = 0; i < curveSegments.length(); ++i) {
    8.     AcDbEntity* pEntity = static_cast<AcDbEntity*>(curveSegments[i]);
    9.     // Check if the entity is a line, arc, or spline and add it to the polyline
    10.     // You may need to convert arcs and splines to polyline segments
    11. }

    12. // Add the polyline to the drawing and erase the original region if needed
    复制代码

     

     

     

     

    面域转多段线边界
    哎...膜结构车棚,签到来了1...
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|手机版|中国膜结构网_中国空间膜结构协会

    GMT+8, 2024-5-14 04:03 , Processed in 0.060916 second(s), 21 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

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