ObjectARX_椭圆和样条曲线

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

先看一下效果:

ObjectARX_椭圆和样条曲线_第1张图片

主要实现:

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);
}

外接矩形创建椭圆:

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计算俩点间的连线的中点的实现在这里

创建样条曲线:

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);
}

 

转载于:https://my.oschina.net/u/2930533/blog/1584651

你可能感兴趣的:(ObjectARX_椭圆和样条曲线)