找回密码
 立即注册

QQ登录

只需一步,快速开始

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

椭圆

[复制链接]

0

主题

0

回帖

26

积分

管理员

积分
26
发表于 2024-3-6 11:48:43 | 显示全部楼层 |阅读模式
  1. cDbObjectId FymEllipse::Add(const AcGePoint3d& ptCenter, const AcGeVector3d& vecNormal, const AcGeVector3d& majorAxis, double ratio)
  2. {//缺省的两个参数为椭圆起始弧度与终止弧度,ratio为大半径与小半径比
  3.         AcDbEllipse* pEllipse = new AcDbEllipse(ptCenter, vecNormal, majorAxis, ratio);
  4.         return FymDatabase::PostToModelSpace(pEllipse);
  5. }
  6. AcDbObjectId FymEllipse::Add(const AcGePoint2d& pt1, const AcGePoint2d& pt2) {
  7.         AcGePoint3d ptCenter;
  8.         ptCenter = FymGeometry::GetMiddlePt(FymConverUtil::ToPoint3d(pt1), FymConverUtil::ToPoint3d(pt2));
  9.         AcGeVector3d vecNormal(0, 0, 1);
  10.         AcGeVector3d majorAxis(fabs(pt1.x - pt2.x) / 2, 0, 0);
  11.         double ratio = fabs((pt1.y - pt2.y) / (pt1.x - pt2.x));
  12.         return Add(ptCenter, vecNormal, majorAxis, ratio);
  13. }
  14. AcDbObjectId FymEllipse::Add(const AcGePoint2d& pt1, const AcGePoint2d& pt2, const AcGePoint2d& pt3)
  15. {
  16.         AcGePoint3d ptCenter;
  17.         ptCenter = FymGeometry::GetMiddlePt(FymConverUtil::ToPoint3d(pt1), FymConverUtil::ToPoint3d(pt2));
  18.         AcGeVector3d vecNormal(0, 0, 1);
  19.         double ellipseAsq = pow(pt1.x - ptCenter.x, 2) + pow(pt1.y - ptCenter.y, 2);
  20.         double ellipseBsq = pow(pt3.x - ptCenter.x, 2) + pow(pt3.y - ptCenter.y, 2);
  21.         AcGeVector3d majorAxis;
  22.         double ratio;
  23.         if (ellipseAsq > ellipseBsq)
  24.         {
  25.                 majorAxis = AcGeVector3d((ptCenter.x - pt1.x), (ptCenter.y - pt1.y), 0.0);
  26.                 ratio = sqrt(ellipseBsq/ellipseAsq);
  27.         }
  28.         else
  29.         {
  30.                 majorAxis = AcGeVector3d((ptCenter.x - pt3.x), (ptCenter.y - pt3.y), 0.0);
  31.                 ratio = sqrt(ellipseAsq/ellipseBsq);
  32.         }
  33.         return Add(ptCenter, vecNormal, majorAxis, ratio);
  34. }
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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