请选择 进入手机版 | 继续访问电脑版
天气与日历 切换到窄版

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

[每日一码] (4)获得准确的AcDb3dSolid的包围盒

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

    [LV.5]常住居民I

    1263

    主题

    149

    回帖

    214748万

    积分

    管理员

    积分
    2147483647
    发表于 2024-2-23 22:20:01 | 显示全部楼层 |阅读模式
    1. void asdkasdktightboundbox()
    2. {
    3.     ads_name eName;
    4.     ads_point pt;


    5.     if( RTNORM != acedEntSel("\nPlease select a solid ", eName, pt ))
    6.         return;


    7.     AcDbObjectId id;
    8.     acdbGetObjectId( id, eName );
    9.     AcDb3dSolid*pSolid = NULL;


    10.     acdbOpenObject(pSolid, id, AcDb::kForRead );
    11.     if( pSolid == NULL ) {
    12.         acutPrintf("\nObject not a solid");
    13.         return;
    14.     }


    15.     double volume;
    16.     AcGePoint3d centroid;
    17.     double momInertia[3];
    18.     double prodInertia[3];
    19.     double prinMoments[3];
    20.     AcGeVector3d prinAxes[3];
    21.     double radiiGyration[3];


    22.     AcDbExtents extents;


    23.     Acad::ErrorStatus es;
    24.     es = pSolid->getMassProp(
    25.                 volume,
    26.                 centroid,
    27.                 momInertia,
    28.                 prodInertia,
    29.                 prinMoments,
    30.                 prinAxes,
    31.                 radiiGyration,
    32.                 extents);
    33.     AcGePoint3d max = extents.maxPoint();
    34.     AcGePoint3d min = extents.minPoint();


    35.     int xAxis, zAxis;
    36.     double bigVol = (max.x - min.x ) * ( max. y - min.y ) * (max.z - min.z);
    37.     acutPrintf("\ncalculated original box ");
    38.     acutPrintf("\nvolume %e", bigVol );
    39.     acutPrintf("\nOriginal box is %e the size of the object", bigVol/volume );


    40.     // some work to make x the largest prin axis, and z the smallest.
    41.     if(prinMoments[0] > prinMoments[1] )
    42.     {
    43.         xAxis = 0;
    44.         zAxis = 1;
    45.     }
    46.     else
    47.     {
    48.         xAxis = 1;
    49.         zAxis = 0;
    50.     }



    51.     if(prinMoments[zAxis] > prinMoments[2] )
    52.         zAxis =  2;
    53.     else if(prinMoments[xAxis] < prinMoments[2] )
    54.         xAxis = 2;



    55.     AcGeMatrix3d mat;
    56.     AcGeVector3d yAxisVec = prinAxes[zAxis].crossProduct( prinAxes[xAxis]);
    57.     mat.setCoordSystem( centroid, prinAxes[xAxis], yAxisVec, prinAxes[zAxis]);
    58.     acutPrintf("\nxAxis %e %e %e", prinAxes[xAxis].x, prinAxes[xAxis].y,prinAxes[xAxis].z);
    59.     acutPrintf("\nyAxis %e %e %e", yAxisVec.x, yAxisVec.y, yAxisVec.z);
    60.     acutPrintf("\nzAxis %e %e %e", prinAxes[zAxis].x, prinAxes[zAxis].y,prinAxes[zAxis].z);


    61.     AcDbEntity*pNewEnt = NULL;


    62.     es = pSolid->getTransformedCopy( mat.inverse(), pNewEnt );
    63.     if( pNewEnt == NULL )
    64.     {
    65.         acutPrintf("\nCannot transform solid");
    66.         acutPrintf("\nError: %s", acadErrorStatusText(es));
    67.         pSolid->close();
    68.         return;
    69.     }


    70.     AcDbExtents newExtents;
    71.     pNewEnt->getGeomExtents( newExtents );
    72.     delete pNewEnt;
    73.     //delete pNewEnt;
    74.     max = newExtents.maxPoint();
    75.     min = newExtents.minPoint();
    76.     double deltaX = (max.x - min.x );
    77.     double deltaY = ( max. y - min.y );
    78.     double deltaZ = (max.z - min.z );
    79.     double smallVol = deltaX * deltaY * deltaZ;


    80.     acutPrintf("\ncalculated smaller box ");
    81.     acutPrintf("\nvolume %e", smallVol );
    82.     acutPrintf("\nAligned box is %e the size of the object", smallVol/volume );
    83.     acutPrintf("\nOriginal box is %e the size of the aligned box", bigVol/smallVol);


    84.     AcDb3dSolid*pNewSolid = new AcDb3dSolid;
    85.     pNewSolid->createBox(deltaX, deltaY, deltaZ );
    86.     AcGePoint3d newBoxCenter = min + 0.5 * (max - min);
    87.     pNewSolid->transformBy( mat * AcGeMatrix3d::translation( newBoxCenter - AcGePoint3d::kOrigin ) );
    88.     AcDbBlockTableRecord*pRecord;
    89.     acdbOpenObject(pRecord, pSolid->ownerId(), AcDb::kForWrite );
    90.     pSolid->close();

    91.     if( pRecord == NULL )
    92.     {
    93.         acutPrintf("\nCannot open BTR");
    94.         delete pNewSolid;
    95.         return;
    96.     }


    97.     pRecord->appendAcDbEntity(pNewSolid);
    98.     pNewSolid->close();   
    99.     pRecord->close();


    100. }
    复制代码

     

     

     

     

    [每日一码] (4)获得准确的AcDb3dSolid的包围盒
    中国膜结构网打造全中国最好的膜结构综合平台 ,统一协调膜结构设计,膜结构施工,膜材采购,膜材定制,膜结构预算全方位服务。 中国空间膜结构协会合作单位。
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

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

    GMT+8, 2024-3-29 06:39 , Processed in 0.055942 second(s), 21 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

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