|
- 输入三点,以中间点为顶点,把旁边两条线做圆角,半径用户输入
- static void TESTcomplexentcmd()
- {
- ads采用point pt1;
- ads采用point pt2;
- ads采用point pt3;
- ads采用real r;
- if (acedGetPoint(NULL,采用T("\n输入第一点"),pt1) != RTNORM)
- {
- return;
- }
- if (acedGetPoint(NULL,采用T("\n输入第二点"),pt2) != RTNORM)
- {
- return;
- }
- if (acedGetPoint(NULL,采用T("\n输入第三点"),pt3) != RTNORM)
- {
- return;
- }
- if (acedGetReal(采用T("\n输入内切圆半径"),&r) != RTNORM)
- {
- return;
- }
- ////坐标维度转化
- AcGePoint3d pt3d1 = asPnt3d(pt1);
- AcGePoint3d pt3d2 = asPnt3d(pt2);
- AcGePoint3d pt3d3 = asPnt3d(pt3);
- ////构造两条直线计算顶点到切点的距离
- AcDbLine line1(pt3d2,pt3d1);
- AcDbLine line2(pt3d2,pt3d3);
- ////得到以PT2为顶点的两个向量
- AcGeVector3d v1(pt1[X]-pt2[X],pt1[Y]-pt2[Y],pt1[Z] - pt2[Z]);
- AcGeVector3d v2(pt3[X]-pt2[X],pt3[Y] - pt2[Y],pt3[Z] - pt2[Z]);
- AcGeVector3d v3(0,0,1);
- double PI = 3.1415926536;
- ////计算两个向量的夹角
- double angle = v1.angleTo(v2,v3);
- double angle1 = angle > PI ? 2 * PI - angle : angle;
- ////计算切点到顶点距离
- double dist = r / tan(angle1 / 2);
- ////切点1
- AcGePoint3d ptQ1;
- ////切点2
- AcGePoint3d ptQ2;
- ////找到切点
- line1.getPointAtDist(dist,ptQ1);
- line2.getPointAtDist(dist,ptQ2);
- ////求出bulge值(是圆心角1/4的正切值 - - ,之前当成正切值的四分之一了 - -!!!)
- double bulge;
- bulge = tan((PI - angle1) / 4);
- if(angle > 0 && angle <= PI)
- {
- bulge = - bulge;
- }
- AcDbPolyline* pl = new AcDbPolyline();
- AcGePoint2d pt2d1(pt3d1[X],pt3d1[Y]);
- AcGePoint2d pt2dq1(ptQ1[X],ptQ1[Y]);
- AcGePoint2d pt2dq2(ptQ2[X],ptQ2[Y]);
- AcGePoint2d pt2d3(pt3d3[X],pt3d3[Y]);
- pl->addVertexAt(0,pt2d1,0);
- pl->addVertexAt(1,pt2dq1,bulge);
- pl->addVertexAt(2,pt2dq2,0);
- pl->addVertexAt(3,pt2d3,0);
- LoadEntity(pl);
- CString out;
- out.Format(采用T("\nangle:%.2f,bulge:%.2f,\ndist:%.2f\n,pt[z]:%.2f,%.2f,%.2f"),angle,bulge,dist,pt1[Z],pt2[Z],pt3[Z]);
- acutPrintf(out);
- }
复制代码 |
|