先看一下效果:app
主要實現:.net
void ZffCHAP2AddEllipse() { // 使用中心點、所在平面、長軸矢量和短長軸比例來建立橢圓 AcGeVector3d vecNormal(0, 0, 1); AcGeVector3d majorAxis(40, 0, 0); AcDbObjectId entId; entId = CCreateEnt::CreateEllipse(AcGePoint3d::kOrigin, vecNormal,majorAxis, 0.5); // 使用外接矩形來建立橢圓 AcGePoint2d pt1(60, 80), pt2(140, 120); CCreateEnt::CreateEllipse(pt1, pt2); } void ZffCHAP2AddSpline() { // 使用樣本點直接建立樣條曲線 AcGePoint3d pt1(0, 0, 0), pt2(10, 30, 0), pt3(60, 80, 0), pt4(100, 100,0); AcGePoint3dArray points; points.append(pt1); points.append(pt2); points.append(pt3); points.append(pt4); CCreateEnt::CreateSpline(points); // 指定起始點和終止點的切線方向,建立樣條曲線 pt2.set(30, 10, 0); pt3.set(80, 60, 0); points.removeSubArray(0, 3); points.append(pt1); points.append(pt2); points.append(pt3); points.append(pt4); AcGeVector3d startTangent(5, 1, 0); AcGeVector3d endTangent(5, 1, 0); CCreateEnt::CreateSpline(points, startTangent, endTangent); }
外接矩形建立橢圓:3d
AcDbObjectId CCreateEnt::CreateEllipse(AcGePoint2d pt1, AcGePoint2d pt2) { // 計算橢圓的中心點 AcGePoint3d ptCenter; ptCenter = CCalculation::MiddlePoint(CCalculation::Pt2dTo3d(pt1), CCalculation::Pt2dTo3d(pt2)); AcGeVector3d vecNormal(0, 0, 1); AcGeVector3d majorAxis(fabs(pt1.x - pt2.x) / 2, 0, 0); double ratio = fabs((pt1.y - pt2.y) / (pt1.x - pt2.x)); return CCreateEnt::CreateEllipse(ptCenter, vecNormal, majorAxis, ratio); }
https://my.oschina.net/u/2930533/blog/edit/760855計算倆點間的連線的中點的實如今這裏code
建立樣條曲線:orm
AcDbObjectId CCreateEnt::CreateSpline(const AcGePoint3dArray& points,int order, double fitTolerance) { assert (order >= 2 && order <= 26); AcDbSpline *pSpline = new AcDbSpline(points, order, fitTolerance); AcDbObjectId splineId; splineId = CCreateEnt::PostToModelSpace(pSpline); return splineId; }
AcDbObjectId CCreateEnt::CreateSpline(const AcGePoint3dArray& points,const AcGeVector3d&startTangent, const AcGeVector3d&endTangent,int order, double fitTolerance) { assert(order >= 2 && order <= 26); AcDbSpline *pSpline = new AcDbSpline(points, startTangent,endTangent,order, fitTolerance); return CCreateEnt::PostToModelSpace(pSpline); }