- UID
- 3407
- 积分
- 56
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-3-29
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2002-5-27 21:23:21
|
显示全部楼层
//已知2个AcDb2dPolyline线的id(可以任意个顶点),计算它们之间的最小值
int GetMinDistBy2Polyline(AcDbObjectId id1,AcDbObjectId id2,
double &dMinDist)
{
int iRz;
AcGeDoubleArray dDists;
//得到该实体的点集
AcGePoint3dArray pts1,pts2;
AcGeDoubleArray dBlgs1,dBlgs2;
iRz=GetCurveParam(id1, &pts1, &dBlgs1);
if(iRz==0)
{
return 0;
}
iRz=GetCurveParam(id2, &pts2, &dBlgs2);
if(iRz==0)
{
return 0;
}
//循环求实数集
for (int i=0;i<pts1.length()-1;i++)
{
for(int j=0;j<pts2.length()-1;j++)
{
double dMinD;
iRz=GetMinDistanceFor2Id(pts1,pts1[i+1],dBlgs1,
pts2[j],pts2[j+1],dBlgs2[j],dMinD);
if(iRz==0)
{
return 0;
}else
{
dDists.append(dMinD);
}
}
}
//求实数集中的最小值
double dMaxD;
iRz=GetDoubleArrayMinMax(dDists,dMinDist,dMaxD);
if(iRz==0)
{
return 0;
}
return 1;
}
//已知两个实体(可能是直线,可能是圆弧,规定只有2个顶点,我称之为单位实体),求它们最近距离
int GetMinDistanceFor2Id(AcGePoint3d g3Sp1,AcGePoint3d g3Ep1,double dBlg1,
AcGePoint3d g3Sp2,AcGePoint3d g3Ep2,double dBlg2,
double & dMinDist)
{
int iRz;
AcGeDoubleArray dDists;
double dMaxDist;
if(fabs(dBlg1)<1.e-5&&fabs(dBlg2)<1.e-5)//2个直线
{
AcGePoint3d g3MinSP1,g3MinSP2,g3MinEP1,g3MinEP2;
//2个几何直线
AcGeLineSeg3d geLS1(g3Sp1,g3Ep1),geLS2(g3Sp2,g3Ep2);
//4个最近点,4个最近距离
g3MinSP1=geLS2.closestPointTo(g3Sp1);
dDists.append(g3MinSP1.distanceTo(g3Sp1));
g3MinSP2=geLS1.closestPointTo(g3Sp2);
dDists.append(g3MinSP2.distanceTo(g3Sp2));
g3MinEP1=geLS2.closestPointTo(g3Ep1);
dDists.append(g3MinEP1.distanceTo(g3Ep1));
g3MinEP2=geLS1.closestPointTo(g3Ep2);
dDists.append(g3MinEP2.distanceTo(g3Ep2));
//求该实数集中的最小值
iRz=GetDoubleArrayMinMax(dDists,dMinDist,dMaxDist);
if(iRz==0)
{
return 0;
}
}else if(fabs(dBlg1)<1.e-5&&fabs(dBlg2)>1.e-5)//直线和圆弧
{
iRz=GetMinDistForArcLineSeg(g3Sp2,g3Ep2,dBlg2,g3Sp1,g3Ep1,dMinDist);
if(iRz==0)
{
return 0;
}
}else if(fabs(dBlg1)>1.e-5&&fabs(dBlg2)<1.e-5)//圆弧和直线
{
iRz=GetMinDistForArcLineSeg(g3Sp1,g3Ep1,dBlg1,g3Sp2,g3Ep2,dMinDist);
if(iRz==0)
{
return 0;
}
}else if(fabs(dBlg1)>1.e-5&&fabs(dBlg2)>1.e-5)//圆弧和圆弧
{
iRz=GetMinDistFor2Arc(g3Sp1,g3Ep1,dBlg1,g3Sp2,g3Ep2,dBlg2,dMinDist);
if(iRz==0)
{
return 0;
}
}
return 1;
}
//已知一个实数集,求其中的最小值和最大值
int GetDoubleArrayMinMax(AcGeDoubleArray dNums,
double &dMin,
double &dMax)
{
if(dNums.length()==0)
{
return 0;
}
dMin=dMax=dNums[0];
for(int i=0;i<dNums.length();i++)
{
if(dMin>dNums)
{
dMin=dNums;
}
if(dMax<dNums)
{
dMax=dNums;
}
}
return 1;
}
//已知圆弧和直线,求其中最近距离
int GetMinDistForArcLineSeg(AcGePoint3d g3Sp1,AcGePoint3d g3Ep1,double dBlg,
AcGePoint3d g3Sp2,AcGePoint3d g3Ep2,double & dMinDist)
{
int iRz;
AcGeDoubleArray dDists;
double dMaxDist;
//4个最近点
AcGePoint3d g3MinSP1,g3MinSP2,g3MinEP1,g3MinEP2;
//几何圆弧和几何直线
AcGeLineSeg3d geLS(g3Sp2,g3Ep2);
AcGePoint3d g3ArcMidPt;
iRz=GetArcMidPoint(g3Sp1,g3Ep1,dBlg,g3ArcMidPt);
if(iRz==0)
{
return 0;
}
AcGeCircArc3d geArc(g3Sp1,g3ArcMidPt,g3Ep1);
//4个最近点,4个最近距离
g3MinSP1=geLS.closestPointTo(g3Sp1);
dDists.append(g3MinSP1.distanceTo(g3Sp1));
g3MinSP2=geArc.closestPointTo(g3Sp2);
dDists.append(g3MinSP2.distanceTo(g3Sp2));
g3MinEP1=geLS.closestPointTo(g3Ep1);
dDists.append(g3MinEP1.distanceTo(g3Ep1));
g3MinEP2=geArc.closestPointTo(g3Ep2);
dDists.append(g3MinEP2.distanceTo(g3Ep2));
//求圆心到线段的最近距离
AcGePoint3d g3MinCp;
//求圆弧圆心和半径
fast_arc ark(g3Sp1,g3Ep1,dBlg);
AcGePoint3d g3Cp;
double dRad;
g3Cp=ark.fast_arc_getcenPoint();
dRad=ark.fast_arc_getradius();
g3MinCp=geLS.closestPointTo(g3Cp);
AcGeLineSeg3d g3LineSeg(g3Cp,g3MinCp);//
int intn;
AcGePoint3d p1,p2;
int iRz1=0;
if(iRz1=geArc.intersectWith(g3LineSeg,intn,p1,p2))
{
dDists.append(g3MinCp.distanceTo(g3Cp)-dRad);
}
//求该实数集中的最小值
iRz=GetDoubleArrayMinMax(dDists,dMinDist,dMaxDist);
if(iRz==0)
{
return 0;
}
return 1;
}
//已知圆弧起点和终点和突起值,求圆弧中点
int GetArcMidPoint(AcGePoint3d g3Sp,AcGePoint3d g3Ep,double dBlg,
AcGePoint3d &g3ArcMidPt)
{
int iRz=0;
//求圆弧圆心和半径
fast_arc ark(g3Sp,g3Ep,dBlg);
AcGePoint3d g3Cp;
double dRad;
g3Cp=ark.fast_arc_getcenPoint();
dRad=ark.fast_arc_getradius();
if(fabs((fabs(dBlg)-1))<1.e-5)//是半园
{
AcGeVector3d v3Sp=g3Sp-g3Cp;
AcGeVector3d v3k(0.0,0.0,1.0);
if(dBlg>0)//逆时针
{
v3Sp.rotateBy(3.1415926/2,v3k);
}else//顺时针
{
v3Sp.rotateBy(3.1415926/2,-v3k);
}
g3ArcMidPt=g3Cp+v3Sp;
}else
{
//求弦中点
double dAng;
AcGeVector3d v3Sp,v3Ep;
AcGeVector3d v3K(0.0,0.0,1.0);
v3Sp=g3Sp-g3Cp;
v3Ep=g3Ep-g3Cp;
if(dBlg>0)//逆时针
{
dAng=v3Sp.angleTo(v3Ep,v3K);
v3Sp.rotateBy(dAng/2,v3K);
}else//顺时针
{
dAng=v3Sp.angleTo(v3Ep,-v3K);
v3Sp.rotateBy(dAng/2,-v3K);
}
g3ArcMidPt=g3Cp+v3Sp;
}
return 1;
}
//已知2圆弧,求其中最近距离
int GetMinDistFor2Arc(AcGePoint3d g3Sp1,AcGePoint3d g3Ep1,double dBlg1,
AcGePoint3d g3Sp2,AcGePoint3d g3Ep2,double dBlg2,
double & dMinDist)
{
int iRz;
AcGePoint3d g3ArcMidPt1,g3ArcMidPt2;
iRz=GetArcMidPoint( g3Sp1, g3Ep1, dBlg1,g3ArcMidPt1);
if(iRz==0)
{
return 0;
}
iRz=GetArcMidPoint( g3Sp2, g3Ep2, dBlg2,g3ArcMidPt2);
if(iRz==0)
{
return 0;
}
//求2个圆心
AcGePoint3d g3Cp1,g3Cp2;
double dRad1,dRad2;
fast_arc ark1(g3Sp1,g3Ep1,dBlg1);
g3Cp1=ark1.fast_arc_getcenPoint();
dRad1=ark1.fast_arc_getradius();
fast_arc ark2(g3Sp2,g3Ep2,dBlg2);
g3Cp2=ark2.fast_arc_getcenPoint();
dRad2=ark2.fast_arc_getradius();
//构造几何圆弧,几何线段(圆心线段)
AcGeCircArc3d geArc1(g3Sp1,g3ArcMidPt1,g3Ep1);
AcGeCircArc3d geArc2(g3Sp2,g3ArcMidPt2,g3Ep2);
AcGeLineSeg3d geLineSeg(g3Cp1,g3Cp2);
int intn;
AcGePoint3d p1,p2;
int intn1;
AcGePoint3d pp1,pp2;
int iRz1,iRz2;
if((iRz2=geArc2.intersectWith(geLineSeg,intn1,pp1,pp2))&&
(iRz1=geArc1.intersectWith(geLineSeg,intn,p1,p2)))
{
dMinDist=g3Cp1.distanceTo(g3Cp2)-(dRad1+dRad2);
}else
{
AcGeDoubleArray dDists;
//4个最近点
AcGePoint3d g3MinSP1,g3MinSP2,g3MinEP1,g3MinEP2;
//4个最近点,4个最近距离
g3MinSP1=geArc2.closestPointTo(g3Sp1);
dDists.append(g3MinSP1.distanceTo(g3Sp1));
g3MinSP2=geArc1.closestPointTo(g3Sp2);
dDists.append(g3MinSP2.distanceTo(g3Sp2));
g3MinEP1=geArc2.closestPointTo(g3Ep1);
dDists.append(g3MinEP1.distanceTo(g3Ep1));
g3MinEP2=geArc1.closestPointTo(g3Ep2);
dDists.append(g3MinEP2.distanceTo(g3Ep2));
//求该实数集中的最小值
double dMaxDist;
iRz=GetDoubleArrayMinMax(dDists,dMinDist,dMaxDist);
if(iRz==0)
{
return 0;
}
}
return 1;
} |
|