- UID
- 1
- 积分
- 16111
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-1-3
- 最后登录
- 1970-1-1
|
发表于 2002-11-11 22:59:40
|
显示全部楼层
最初由 efan2000 发布
[B][QUOTE]最初由 烛光 发布
[B]一和二的差别就在于一是根据距离来求,二是根据参数值来求。
距离的一半肯定是中点,充分必要条件。
参数的一半不一定是中点,即不充分也不必要,只有参数值是线性变化的?.. [/B]
不能说错,但是不完全。
我写XDRX_API的时候就注意到了,开始朋友说有BUG,中点有时候对,有的实体不对。后来用了距离的方法。
在ADN开发资料中,ADESK也给了求中点的代码,也是用的距离的一半。
大家看下下面的代码,求POLYLINE任一段的中点,蓝色的注意。
- [FONT=courier new]
- 问题:
- How do I find the midpoint of a curve and the midpoint of each segment for an
- AcDbPolyline?
- 解答:
- The following code finds the midpoint on the [color=blue]perimeter (not the parametric
- space)[/color] of each segment on a curve.
- Acad::ErrorStatus getMidPointOnEachSegOfCrv(AcDbCurve *pCurve)
- {
- Acad::ErrorStatus es;
- AcGePoint3d pt;
- double startParam, endParam;
-
- if(!pCurve->isKindOf(AcDbCurve::desc()))
- {
- acutPrintf("\nSelected entity is not a CURVE derived object");
- return Acad::eInvalidInput;
- }
-
- AcDbPolyline *pPline;
- pPline = AcDbPolyline::cast(pCurve);
- if ( pPline != NULL )
- {
- int num;
- num = pPline->numVerts();
- for( int index=0; index < num-1; index++ )
- {
- if( pPline->segType(index) == AcDbPolyline::kLine )
- {
- AcGeLineSeg2d lineSeg;
- es = pPline->getLineSegAt(index, lineSeg);
- if( Acad::eOk != es )
- {
- acutPrintf("\nFailed to get segment at
- %d.", index);
- return es;
- }
-
- AcGePoint2d pt;
- pt = lineSeg.midPoint();
- acutPrintf("\nMidpoint of %i segment LINE is:
- %f,%f,%f.", index, pt[0], pt[1], pt[2]);
- }
- else if( pPline->segType(index) == AcDbPolyline::kArc )
- {
- AcGeCircArc2d ArcSeg;
- es = pPline->getArcSegAt(index, ArcSeg);
- if( Acad::eOk != es )
- {
- acutPrintf("\nFailed to get segment at
- %d.", index);
- return es;
- }
-
- double startAng, endAng;
-
- startAng = ArcSeg.startAng();
- endAng = ArcSeg.endAng();
-
- AcGePoint2d pt;
- pt = ArcSeg.evalPoint((startAng+endAng)/2);
-
- acutPrintf("\nMidpoint of %i segment ARC is:
- %f,%f,%f.", index, pt[0], pt[1], pt[2]);
- }
- }
- pPline->close();
- return Acad::eOk;
- }
-
- es = pCurve->getStartParam( startParam );
- if( Acad::eOk != es )
- {
- acutPrintf("\nFailed to get start Parameter.");
- return es;
- }
- acutPrintf("\nstartParam is %fl", startParam);
-
- es = pCurve->getEndParam( endParam );
- if( Acad::eOk != es )
- {
- acutPrintf("\nFailed to get end Parameter.");
- return es;
- }
- acutPrintf("\nendParam is %fl", endParam);
- double distStParam;
- es = pCurve->getDistAtParam( startParam , distStParam);
- if( Acad::eOk != es )
- {
- acutPrintf("\nFailed to get the distance at start Parameter.");
- return es;
- }
-
- double distEndParam;
- es = pCurve->getDistAtParam( endParam , distEndParam);
- if( Acad::eOk != es )
- {
- acutPrintf("\nFailed to get the distance at end Parameter.");
- return es;
- }
-
- if(distStParam > 1.e-10)
- {
- acutPrintf("\nWARNING: The distance at starting parameter is not
- zero. A Trivial situation");
- }
-
- [color=blue]double midDist = distEndParam / 2.0;
-
- es = pCurve->getPointAtDist(midDist, pt);[/color]
- if( Acad::eOk != es )
- {
- acutPrintf("\nFailed to get the distance at end Parameter.");
- return es;
- }
- acutPrintf("\n%f,%f,%f", pt[0], pt[1], pt[2]);
- es = pCurve->close() ;
- if( Acad::eOk != es )
- {
- acutPrintf("\nFailed to get the distance at end Parameter.");
- return es;
- }
-
- return Acad::eOk;
- }
- [/FONT]
复制代码 |
|