OBJECT ARX三维图形绘制
创建三维图形三维长方体==================
static void TESTaddboxcmd(){
AcDb3dSolid* pSolid = new AcDb3dSolid();
Acad::ErrorStatus es = pSolid->createBox(40,50,30);
if(es != Acad::eOk){
acedAlert(采用T("创建长方体失败"));
delete pSolid;
return;
}
//acedAlert(采用T("创建成功"));
使用几何变换矩阵移动长方体
AcGeMatrix3d xform;
AcGeVector3d vec(100,100,100);
xform.setToTranslation(vec);
pSolid->transformBy(xform);
LoadEntity(pSolid);
}
//三维圆锥==============
static void TESTaddcylinedercmd(){
AcDb3dSolid* pSolid = new AcDb3dSolid();
pSolid->createFrustum(30,10,10,0);
LoadEntity(pSolid);
}
三维弹簧
static void TESTaddspirecmd(){
半径和每周在垂直方向的增量
double radius,deltaVertical;
螺旋线的旋转圈数和组成一圈
double number,segment;
radius = 30,deltaVertical = 12;
number = 5,segment = 30;
计算点的个数和角度间隔
int n = number * segment;
double angle = 8 * atan(1.0)/segment;
计算控制点的坐标
AcGePoint3dArray points;
for(int i = 0;i < n + 1;i ++){
AcGePoint3d vertex;
vertex = radius * cos(8 * i *
atan(1.0) / segment);
vertex = radius * sin(8 * i *
atan(1.0) / segment);
vertex = i * deltaVertical / segment;
points.append(vertex);
}
创建螺旋路径
AcDb3dPolyline* p3dPoly = new
AcDb3dPolyline(AcDb::k3dSimplePoly,
points);
AcDbObjectId spireId = LoadEntity(p3dPoly);
这时已经创建了2D模型,增加3D圆截面
AcGeVector3d vec(0,1,0);
AcGePoint3d ptCenter(30,0,0);
AcDbCircle* pCircle = new AcDbCircle(ptCenter,
vec,3);
AcDbObjectId circleId = LoadEntity(pCircle);
根据圆创建面域
AcDbObjectIdArray boundaryIds,regionIds;
boundaryIds.append(circleId);
regionIds = CreateRegion(boundaryIds);
打开拉伸截面和拉伸路径
AcDbRegion* pRegion;
acdbOpenObject(pRegion,regionIds.at(0),AcDb::kForRead);
AcDb3dPolyline* pPoly;
acdbOpenObject(pPoly,spireId,AcDb::kForRead);
进行拉伸操作
AcDb3dSolid* pSolid = new AcDb3dSolid();
pSolid->extrudeAlongPath(pRegion,pPoly);
LoadEntity(pSolid);
pPoly->close();
pRegion->close();
}
多段线形成面域旋转=============
static void TESTaddreventcmd(){
AcGePoint3d vertex;
vertex = AcGePoint3d(15,0,0);
vertex = AcGePoint3d(45,0,0);
vertex = AcGePoint3d(35,10,0);
vertex = AcGePoint3d(41,18,0);
vertex = AcGePoint3d(15,20,0);
AcGePoint3dArray points;
for(int i = 0;i < 5; i++){
points.append(vertex);
}
创建作为旋转截面的多段线
AcDb3dPolyline* p3dPoly = new AcDb3dPolyline(AcDb::k3dSimplePoly,points,true);
AcDbObjectId polyId = LoadEntity(p3dPoly);
将闭合的多段线转化为面域
AcDbObjectIdArray boundaryIds,regionIds;
boundaryIds.append(polyId);
regionIds = CreateRegion(boundaryIds);
进行旋转操作
AcDbRegion* pRegion;
Acad::ErrorStatus es = acdbOpenObject(pRegion,regionIds.at(0),
AcDb::kForRead);
AcDb3dSolid* pSolid = new AcDb3dSolid();
es = pSolid->revolve(pRegion,AcGePoint3d::kOrigin,
AcGeVector3d(0,1,0),8 * atan(1.0));
LoadEntity(pSolid);
pRegion->close();
}
页:
[1]