圆
AcDbObjectId FymCircle::Add(const AcGePoint3d& centerPt, const AcGeVector3d& normal, double radius){
AcDbCircle* pcir = new AcDbCircle(centerPt, normal, radius);
return FymDatabase::PostToModelSpace(pcir);
}
AcDbObjectId FymCircle::Add(const AcGePoint3d& centerPt, double radius)
{
AcGeVector3d vec(0, 0, 1);//默认normal
return Add(centerPt, vec, radius);
}
AcDbObjectId FymCircle::Add(const AcGePoint2d& point1, const AcGePoint2d& point2)//点在圆上
{
AcGePoint2d center = FymGeometry::GetMiddlePt(point1, point2);
AcGePoint3d center3d(center.x, center.y, 0.0);
double radius = center.distanceTo(point1);//中点和点1距离
return Add(center3d, radius);
}
AcDbObjectId FymCircle::AddByMath(const AcGePoint2d& point1, const AcGePoint2d& point2, const AcGePoint2d& point3)
{
double xysm = 0, xyse = 0, xy = 0;
AcGePoint3d ptCenter;
double radius = 0;
//sqrt为求平方根函数
xy = pow(point1.x, 2) + pow(point2.y, 2);
xyse = xy - pow(point3.x, 2) - pow(point3.y, 2);
xysm = xy - pow(point2.x, 2) - pow(point2.y, 2);
xy = (point1.x - point2.x) * (point1.y - point3.y) - (point1.x - point3.x) * (point1.y - point2.y);
//fabs为绝对值函数
if (fabs(xy) < 0.000001)
{
AfxMessageBox(采用T("输入参数无效,不能创建图形!"));
return AcDbObjectId::kNull;
}
ptCenter.x = (xysm * (point1.y - point3.y) - xyse * (point1.y - point2.y)) / (2 * xy);
ptCenter.y = (xysm * (point1.x - point2.x) - xysm * (point1.x - point3.x)) / (2 * xy);
ptCenter.z = 0.0;
//sqrt为求平方根函数
radius = sqrt((point1.x - ptCenter.x) * (point1.x - ptCenter.x) + (point1.y - ptCenter.y) * (point1.y - ptCenter.y));
if (radius < 0.0000001)
{
AfxMessageBox(采用T("半径过小!"));//在CAD界面弹出消息框
return AcDbObjectId::kNull;
}
return Add(ptCenter, radius);
}
AcDbObjectId FymCircle::Add(const AcGePoint2d& point1, const AcGePoint2d& point2, const AcGePoint2d& point3)
{
AcGeCircArc2d geArc(point1, point2, point3);
AcGePoint3d center(geArc.center().x, geArc.center().y, 0.0);
return Add(center, geArc.radius());
}
页:
[1]