小弟遇到难题了,百思不得其解啊
最近想做一条多段线顶点压缩,条件如下:首先将一条多段线的首尾相连,然后求出个点到该连线的距离,求出最大值的点,用该最大值和事先给定的阀值比较,若大于阀值,则保留该点,若小于阀值,则删除该点,再将该点和首尾点各自相连,设起点到该点的连线为L1,该点到结束点的连线为L2,然后用同样的方法依次求出在起点到该点之间的点到L1的距离,求出最大值的点,同理,求出到L2最大距离的点,继续和阀值比较,依次类推,求出满足条件的所有的点,最后将这些点连成一条新的多段线,这就是压缩过的多段线,部分代码如下://<BR>#include "StdAfx.h"<BR>#include "StdArx.h"<BR>#include"acedads.h"<BR>#include"adscodes.h"<BR>#include <stdlib.h><BR>#include <rxobject.h><BR>#include <rxregsvc.h><BR>#include <aced.h><BR>#include <dbents.h><BR>#include <adslib.h><BR>#include <geassign.h><BR>#include "math.h"<BR>double pt,h;<BR>double v=10;<BR>void listPline();<BR>void iterate(AcDbObjectId id);<BR>int maxi(int,int);<BR>void studyaaddd()<BR>{<BR>listPline();<BR>}<BR>void<BR>listPline()<BR>{<BR> int rc;<BR> ads_name en;<BR> AcGePoint3d pt;<BR> rc = acedEntSel("\nSelect a polyline: ", en,<BR> asDblArray(pt));if (rc != RTNORM) {<BR> acutPrintf("\nError during object selection");<BR> return;<BR> }
AcDbObjectId eId;<BR> acdbGetObjectId(eId, en);
AcDbObject *pObj;<BR> acdbOpenObject(pObj, eId, AcDb::kForRead);<BR> if (pObj->isKindOf(AcDb2dPolyline::desc())) {<BR> pObj->close();<BR> iterate(eId);<BR> } else {<BR> pObj->close();<BR> acutPrintf("\nSelected entity is not an AcDb2dPolyline. \nMake sure the setvar PLINETYPE is set to 0 before createing a polyline");<BR> }<BR>}<BR>void<BR>iterate(AcDbObjectId plineId)<BR>{<BR> AcDb2dPolyline *pPline;<BR> acdbOpenObject(pPline, plineId, AcDb::kForRead);
AcDbObjectIterator *pVertIter= pPline->vertexIterator();<BR> pPline->close();
AcDb2dVertex *pVertex;<BR> AcGePoint3d location;<BR> AcDbObjectId vertexObjId;<BR> int i=0;<BR> for (int vertexNumber = 0;!pVertIter->done();<BR> vertexNumber++,pVertIter->step())<BR> {<BR> vertexObjId = pVertIter->objectId();<BR> acdbOpenObject(pVertex, vertexObjId,<BR> AcDb::kForRead);<BR> location = pVertex->position();<BR> pt=float(location);<BR> pt=float(location);<BR> pt=float(location);<BR> pVertex->close();<BR> <BR> acutPrintf("\npt[%d]=%.4f,pt[%d]=%.4f,pt[%d]=%.4f",<BR> i,location,i,location,i,location);<BR> i++;<BR> }
delete pVertIter;<BR> acutPrintf("\n总共%d个顶点",i);<BR> int m,n;<BR> n=i-1;<BR> double max1,a1,b1,c1,e1,s1;<BR> b1=sqrt((pt-pt)*(pt-pt)+(pt-pt)*(pt-pt));<BR> a1=sqrt((pt-pt)*(pt-pt)+(pt-pt)*(pt-pt));<BR> c1=sqrt((pt-pt)*(pt-pt)+(pt-pt)*(pt-pt));<BR> e1=(a1+b1+c1)/2;<BR> s1=sqrt(e1*(e1-a1)*(e1-b1)*(e1-c1));<BR> max1=(2*s1)/a1;<BR> <BR>switch(i)<BR>{case 2:acutPrintf("\n不符合条件,无法求距离!");return;<BR> case 3:acutPrintf("\n第2点距离为%f:",max1);<BR> acutPrintf("\n无最大值!");<BR>}<BR>if(i>3)<BR>{ <BR> acutPrintf("\n该点为pt[%d]且最大值h[%d]=%lf",m,m,h);<BR>for(m=maxi(0,n);p=maxi(0,n);n-p>1;m>1;m=maxi(0,m);p=maxi(p,n))<BR>{k1=maxi(maxi(0,m),m);<BR> u1=maxi(p,maxi(p,n));<BR>for(k2=k1;k3=k1;m-k3>1;k2-maxi(0,m)>1;k2=maxi(maxi(0,m),k2);k3=maxi(k3,m))
<BR>}<BR>} <BR>int maxi(int x,int y)<BR>{int z;<BR>double a,b,c,e,s,max=0;<BR>for(int j=x+1;j<y;j++)<BR>{a=sqrt((pt-pt)*(pt-pt)+(pt-pt)*(pt-pt));<BR> b=sqrt((pt-pt)*(pt-pt)+(pt-pt)*(pt-pt));<BR> c=sqrt((pt-pt)*(pt-pt)+(pt-pt)*(pt-pt));<BR> e=(a+b+c)/2;<BR> s=sqrt(e*(e-a)*(e-b)*(e-c));<BR> h=(2*s)/a;<BR>if(h>max)<BR>{max=h;<BR> z=j;<BR>}<BR>acutPrintf("\nh[%d]=%lf",j,h);<BR>}<BR>acutPrintf("\n第%d点距离最大为%lf:",z+1,max);<BR>return z;<BR>}<BR>在顶点遍历中可能需要采用递归和循环思路,可是我花了好些时间也不能理顺思路,真是急啊,恳请各位高手指点一下有什么好的思路和方法啊,如何去用递归和循环来实现顶点遍历的问题,在下感激不尽!!!!!
页:
[1]