找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 164|回复: 0

[复制链接]

0

主题

0

回帖

26

积分

管理员

积分
26
发表于 2024-3-6 11:48:55 | 显示全部楼层 |阅读模式
  1. AcDbObjectId FymCircle::Add(const AcGePoint3d& centerPt, const AcGeVector3d& normal, double radius)
  2. {
  3.         AcDbCircle* pcir = new AcDbCircle(centerPt, normal, radius);
  4.         return FymDatabase::PostToModelSpace(pcir);
  5. }
  6. AcDbObjectId FymCircle::Add(const AcGePoint3d& centerPt, double radius)
  7. {
  8.         AcGeVector3d vec(0, 0, 1);//默认normal
  9.         return Add(centerPt, vec, radius);
  10. }
  11. AcDbObjectId FymCircle::Add(const AcGePoint2d& point1, const AcGePoint2d& point2)//点在圆上
  12. {
  13.         AcGePoint2d center = FymGeometry::GetMiddlePt(point1, point2);
  14.         AcGePoint3d center3d(center.x, center.y, 0.0);
  15.         double radius = center.distanceTo(point1);//中点和点1距离
  16.         return Add(center3d, radius);
  17. }
  18. AcDbObjectId FymCircle::AddByMath(const AcGePoint2d& point1, const AcGePoint2d& point2, const AcGePoint2d& point3)
  19. {
  20.         double xysm = 0, xyse = 0, xy = 0;
  21.         AcGePoint3d ptCenter;
  22.         double radius = 0;
  23.         //sqrt为求平方根函数
  24.         xy = pow(point1.x, 2) + pow(point2.y, 2);
  25.         xyse = xy - pow(point3.x, 2) - pow(point3.y, 2);
  26.         xysm = xy - pow(point2.x, 2) - pow(point2.y, 2);
  27.         xy = (point1.x - point2.x) * (point1.y - point3.y) - (point1.x - point3.x) * (point1.y - point2.y);
  28.         //fabs为绝对值函数
  29.         if (fabs(xy) < 0.000001)
  30.         {
  31.                 AfxMessageBox(采用T("输入参数无效,不能创建图形!"));
  32.                 return AcDbObjectId::kNull;
  33.         }
  34.         ptCenter.x = (xysm * (point1.y - point3.y) - xyse * (point1.y - point2.y)) / (2 * xy);
  35.         ptCenter.y = (xysm * (point1.x - point2.x) - xysm * (point1.x - point3.x)) / (2 * xy);
  36.         ptCenter.z = 0.0;
  37.         //sqrt为求平方根函数
  38.         radius = sqrt((point1.x - ptCenter.x) * (point1.x - ptCenter.x) + (point1.y - ptCenter.y) * (point1.y - ptCenter.y));
  39.         if (radius < 0.0000001)
  40.         {
  41.                 AfxMessageBox(采用T("半径过小!"));//在CAD界面弹出消息框
  42.                 return AcDbObjectId::kNull;
  43.         }
  44.         return Add(ptCenter, radius);
  45. }
  46. AcDbObjectId FymCircle::Add(const AcGePoint2d& point1, const AcGePoint2d& point2, const AcGePoint2d& point3)
  47. {
  48.         AcGeCircArc2d geArc(point1, point2, point3);
  49.         AcGePoint3d center(geArc.center().x, geArc.center().y, 0.0);
  50.         return Add(center, geArc.radius());
  51. }
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|膜结构网

GMT+8, 2024-12-28 13:51 , Processed in 0.103162 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表