椭圆
cDbObjectId FymEllipse::Add(const AcGePoint3d& ptCenter, const AcGeVector3d& vecNormal, const AcGeVector3d& majorAxis, double ratio){//缺省的两个参数为椭圆起始弧度与终止弧度,ratio为大半径与小半径比
AcDbEllipse* pEllipse = new AcDbEllipse(ptCenter, vecNormal, majorAxis, ratio);
return FymDatabase::PostToModelSpace(pEllipse);
}
AcDbObjectId FymEllipse::Add(const AcGePoint2d& pt1, const AcGePoint2d& pt2) {
AcGePoint3d ptCenter;
ptCenter = FymGeometry::GetMiddlePt(FymConverUtil::ToPoint3d(pt1), FymConverUtil::ToPoint3d(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 Add(ptCenter, vecNormal, majorAxis, ratio);
}
AcDbObjectId FymEllipse::Add(const AcGePoint2d& pt1, const AcGePoint2d& pt2, const AcGePoint2d& pt3)
{
AcGePoint3d ptCenter;
ptCenter = FymGeometry::GetMiddlePt(FymConverUtil::ToPoint3d(pt1), FymConverUtil::ToPoint3d(pt2));
AcGeVector3d vecNormal(0, 0, 1);
double ellipseAsq = pow(pt1.x - ptCenter.x, 2) + pow(pt1.y - ptCenter.y, 2);
double ellipseBsq = pow(pt3.x - ptCenter.x, 2) + pow(pt3.y - ptCenter.y, 2);
AcGeVector3d majorAxis;
double ratio;
if (ellipseAsq > ellipseBsq)
{
majorAxis = AcGeVector3d((ptCenter.x - pt1.x), (ptCenter.y - pt1.y), 0.0);
ratio = sqrt(ellipseBsq/ellipseAsq);
}
else
{
majorAxis = AcGeVector3d((ptCenter.x - pt3.x), (ptCenter.y - pt3.y), 0.0);
ratio = sqrt(ellipseAsq/ellipseBsq);
}
return Add(ptCenter, vecNormal, majorAxis, ratio);
}
页:
[1]