当前位置:   article > 正文

OBJECT ARX三维图形绘制_acdb3dsolid

acdb3dsolid
  1. 创建三维图形
  2. 三维长方体==================
  3. static void TESTaddboxcmd(){
  4. AcDb3dSolid* pSolid = new AcDb3dSolid();
  5. Acad::ErrorStatus es = pSolid->createBox(40,50,30);
  6. if(es != Acad::eOk){
  7. acedAlert(_T("创建长方体失败"));
  8. delete pSolid;
  9. return;
  10. }
  11. //acedAlert(_T("创建成功"));
  12. 使用几何变换矩阵移动长方体
  13. AcGeMatrix3d xform;
  14. AcGeVector3d vec(100,100,100);
  15. xform.setToTranslation(vec);
  16. pSolid->transformBy(xform);
  17. LoadEntity(pSolid);
  18. }
  19. //三维圆锥==============
  20. static void TESTaddcylinedercmd(){
  21. AcDb3dSolid* pSolid = new AcDb3dSolid();
  22. pSolid->createFrustum(30,10,10,0);
  23. LoadEntity(pSolid);
  24. }
  25. 三维弹簧
  26. static void TESTaddspirecmd(){
  27. 半径和每周在垂直方向的增量
  28. double radius,deltaVertical;
  29. 螺旋线的旋转圈数和组成一圈
  30. double number,segment;
  31. radius = 30,deltaVertical = 12;
  32. number = 5,segment = 30;
  33. 计算点的个数和角度间隔
  34. int n = number * segment;
  35. double angle = 8 * atan(1.0)/segment;
  36. 计算控制点的坐标
  37. AcGePoint3dArray points;
  38. for(int i = 0;i < n + 1;i ++){
  39. AcGePoint3d vertex;
  40. vertex[X] = radius * cos(8 * i *
  41. atan(1.0) / segment);
  42. vertex[Y] = radius * sin(8 * i *
  43. atan(1.0) / segment);
  44. vertex[Z] = i * deltaVertical / segment;
  45. points.append(vertex);
  46. }
  47. 创建螺旋路径
  48. AcDb3dPolyline* p3dPoly = new
  49. AcDb3dPolyline(AcDb::k3dSimplePoly,
  50. points);
  51. AcDbObjectId spireId = LoadEntity(p3dPoly);
  52. 这时已经创建了2D模型,增加3D圆截面
  53. AcGeVector3d vec(0,1,0);
  54. AcGePoint3d ptCenter(30,0,0);
  55. AcDbCircle* pCircle = new AcDbCircle(ptCenter,
  56. vec,3);
  57. AcDbObjectId circleId = LoadEntity(pCircle);
  58. 根据圆创建面域
  59. AcDbObjectIdArray boundaryIds,regionIds;
  60. boundaryIds.append(circleId);
  61. regionIds = CreateRegion(boundaryIds);
  62. 打开拉伸截面和拉伸路径
  63. AcDbRegion* pRegion;
  64. acdbOpenObject(pRegion,regionIds.at(0),AcDb::kForRead);
  65. AcDb3dPolyline* pPoly;
  66. acdbOpenObject(pPoly,spireId,AcDb::kForRead);
  67. 进行拉伸操作
  68. AcDb3dSolid* pSolid = new AcDb3dSolid();
  69. pSolid->extrudeAlongPath(pRegion,pPoly);
  70. LoadEntity(pSolid);
  71. pPoly->close();
  72. pRegion->close();
  73. }
  74. 多段线形成面域旋转=============
  75. static void TESTaddreventcmd(){
  76. AcGePoint3d vertex[5];
  77. vertex[0] = AcGePoint3d(15,0,0);
  78. vertex[1] = AcGePoint3d(45,0,0);
  79. vertex[2] = AcGePoint3d(35,10,0);
  80. vertex[3] = AcGePoint3d(41,18,0);
  81. vertex[4] = AcGePoint3d(15,20,0);
  82. AcGePoint3dArray points;
  83. for(int i = 0;i < 5; i++){
  84. points.append(vertex[i]);
  85. }
  86. 创建作为旋转截面的多段线
  87. AcDb3dPolyline* p3dPoly = new AcDb3dPolyline(AcDb::k3dSimplePoly,points,true);
  88. AcDbObjectId polyId = LoadEntity(p3dPoly);
  89. 将闭合的多段线转化为面域
  90. AcDbObjectIdArray boundaryIds,regionIds;
  91. boundaryIds.append(polyId);
  92. regionIds = CreateRegion(boundaryIds);
  93. 进行旋转操作
  94. AcDbRegion* pRegion;
  95. Acad::ErrorStatus es = acdbOpenObject(pRegion,regionIds.at(0),
  96. AcDb::kForRead);
  97. AcDb3dSolid* pSolid = new AcDb3dSolid();
  98. es = pSolid->revolve(pRegion,AcGePoint3d::kOrigin,
  99. AcGeVector3d(0,1,0),8 * atan(1.0));
  100. LoadEntity(pSolid);
  101. pRegion->close();
  102. }


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/114388
推荐阅读
相关标签
  

闽ICP备14008679号