errBoy 发表于 2005-10-24 18:13:00

请教高手

<P>我是一个初学者</P>
<P>有一个问题想请教高手</P>
<P>在ARX中用什么方法求POLYLINE的两个顶点的连线同X轴的夹角?</P>
<P>希望能有个例子.</P>
<P>在这里先谢谢了</P>

maomao2004 发表于 2005-10-25 16:08:00

<P>void adeskfirst()<BR>{<BR>&nbsp;// TODO: Implement the command<BR>&nbsp;ads_name ent;<BR>&nbsp;ads_point pnt;<BR>&nbsp;int ret = acedEntSel("\nSelect A Entity:",ent,pnt);<BR>&nbsp;if(RTNORM == ret)<BR>&nbsp;{<BR>&nbsp;&nbsp;AcDbObjectId id;<BR>&nbsp;&nbsp;Acad::ErrorStatus es = acdbGetObjectId(id,ent);<BR>&nbsp;&nbsp;assert(Acad::eOk == es);<BR>&nbsp;&nbsp;AcDbEntity *pEnt;<BR>&nbsp;&nbsp;es = acdbOpenAcDbEntity(pEnt,id,AcDb::kForRead);<BR>&nbsp;&nbsp;if(Acad::eOk == es)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;AcDbPolyline *pPl = AcDbPolyline::cast(pEnt);<BR>&nbsp;&nbsp;&nbsp;assert(pPl);<BR>&nbsp;&nbsp;&nbsp;AcGePoint3d startpnt,endpnt;<BR>&nbsp;&nbsp;&nbsp;pPl-&gt;getStartPoint(startpnt);<BR>&nbsp;&nbsp;&nbsp;pPl-&gt;getEndPoint(endpnt);<BR>&nbsp;&nbsp;&nbsp;pPl-&gt;close();<BR>&nbsp;&nbsp;&nbsp;AcGeVector3d vec = endpnt - startpnt;<BR>&nbsp;&nbsp;&nbsp;AcGeVector3d xAxis(1.0,0.0,0.0);<BR>&nbsp;&nbsp;&nbsp;double angle;<BR>&nbsp;&nbsp;&nbsp;angle = vec.angleTo(xAxis,AcGeVector3d(0,0,-1));<BR>&nbsp;&nbsp;&nbsp;angle = angle*180/3.1415926;<BR>&nbsp;&nbsp;}&nbsp;<BR>&nbsp;}</P>
<P>}</P>
<P>这只是对plinetype=2,而且pline只有一节的情况下适用!</P>

errBoy 发表于 2005-10-26 12:19:00

<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dPTS,dPtE是POLY的两个点,.&nbsp; 下面的代码是VBA的,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '''''第一顶点と第二顶点の连结线とX轴の夹角<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dAngSE = ThisDrawing.Utility.AngleFromXAxis(dPTS, dPtE)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '''''第二顶点と第一顶点の连结线とX轴の夹角<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dAngES = ThisDrawing.Utility.AngleFromXAxis(dPtE, dPTS)</P>
<P>上面两句话转换成ARX如下:</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;传入的点值是不变的, 类型为:</P>
<P>&nbsp;AcArray&lt;double&gt;&nbsp;&nbsp; dPTS;<BR>AcArray&lt;double&gt;&nbsp;&nbsp;&nbsp; dPTE;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dAngSE = atan((dPTS.at(1)-dPTE.at(1))/(dPTS.at(0)-dPTE.at(0)));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dAngES = atan((dPTE.at(1)-dPTS.at(1))/(dPTE.at(0)-dPTS.at(0)));</P>
<P>得到的角度是不同的, 不太明白是什么原因还请高手指点呀</P>

errBoy 发表于 2005-10-27 10:14:00

<P>真的很感谢你提供的方法</P>

<P>但现在还存在一个问题<BR>我做的这个东东是要实现VBA的代码的功能<BR>但算的这个角度值,和VBA的有0.0&nbsp; 几的差别,</P>
<P>为什么会这样呢</P>
页: [1]
查看完整版本: 请教高手