如何判断一个点是否在一条直线上?
<P>已知点、线,</P><P>有无函数可以判断该点是否在这条线段上,</P>
<P>或者求出点到这条线段的距离的函数或者方法</P> <PRE class=prog_in_0>Acad::ErrorStatus</PRE><PRE class=prog_in_0>AsdkPoly::intersectWith(</PRE><PRE class=prog_in_0> const AcDbEntity* ent,</PRE><PRE class=prog_in_0> AcDb::Intersect intType,</PRE><PRE class=prog_in_0> const AcGePlane& projPlane,</PRE><PRE class=prog_in_0> AcGePoint3dArray& points,</PRE><PRE class=prog_in_0> int /*thisGsMarker*/,</PRE><PRE class=prog_in_0> int /*otherGsMarker*/) const</PRE><PRE class=prog_in_0>{</PRE><PRE class=prog_in_0> assertReadEnabled();</PRE><PRE class=prog_in_0> Acad::ErrorStatus es = Acad::eOk;</PRE><PRE class=prog_in_0> if (ent == NULL)</PRE><PRE class=prog_in_0> return Acad::eNullEntityPointer;</PRE><PRE class=prog_in_0></PRE><PRE class=prog_in_0> // The idea is to intersect each side of the polygon</PRE><PRE class=prog_in_0> // with the given entity and return all the points.</PRE><PRE class=prog_in_0> // </PRE><PRE class=prog_in_0> // For non-R12-entities, with intersection methods defined,</PRE><PRE class=prog_in_0> // we call that method for each of the sides of the polygon. </PRE><PRE class=prog_in_0> // For R12-entities, we use the locally defined intersectors,</PRE><PRE class=prog_in_0> // since their protocols are not implemented.</PRE><PRE class=prog_in_0> //</PRE><PRE class=prog_in_0> if (ent->isKindOf(AcDbLine::desc())) {</PRE><PRE class=prog_in_0> if ((es = intLine(this, AcDbLine::cast(ent),</PRE><PRE class=prog_in_0> intType, &projPlane, points)) != Acad::eOk)</PRE><PRE class=prog_in_0> {</PRE><PRE class=prog_in_0> return es;</PRE><PRE class=prog_in_0> }</PRE><PRE class=prog_in_0> } else if (ent->isKindOf(AcDbArc::desc())) {</PRE><PRE class=prog_in_0> if ((es = intArc(this, AcDbArc::cast(ent), intType,</PRE><PRE class=prog_in_0> &projPlane, points)) != Acad::eOk)</PRE><PRE class=prog_in_0> {</PRE><PRE class=prog_in_0> return es;</PRE><PRE class=prog_in_0> }</PRE><PRE class=prog_in_0> } else if (ent->isKindOf(AcDbCircle::desc())) {</PRE><PRE class=prog_in_0> if ((es = intCircle(this, AcDbCircle::cast(ent),</PRE><PRE class=prog_in_0> intType, &projPlane, points)) != Acad::eOk)</PRE><PRE class=prog_in_0> {</PRE><PRE class=prog_in_0> return es;</PRE><PRE class=prog_in_0> }</PRE><PRE class=prog_in_0> } else if (ent->isKindOf(AcDb2dPolyline::desc())) {</PRE><PRE class=prog_in_0> if ((es = intPline(this, AcDb2dPolyline::cast(ent),</PRE><PRE class=prog_in_0> intType, &projPlane, points)) != Acad::eOk)</PRE><PRE class=prog_in_0> {</PRE><PRE class=prog_in_0> return es;</PRE><PRE class=prog_in_0> }</PRE><PRE class=prog_in_0> } else if (ent->isKindOf(AcDb3dPolyline::desc())) {</PRE><PRE class=prog_in_0> if ((es = intPline(this, AcDb3dPolyline::cast(ent),</PRE><PRE class=prog_in_0> intType, &projPlane, points)) != Acad::eOk)</PRE><PRE class=prog_in_0> {</PRE><PRE class=prog_in_0> return es;</PRE><PRE class=prog_in_0> }</PRE><PRE class=prog_in_0> } else {</PRE><PRE class=prog_in_0> AcGePoint3dArray vertexArray;</PRE><PRE class=prog_in_0> if ((es = getVertices3d(vertexArray))</PRE><PRE class=prog_in_0> != Acad::eOk)</PRE><PRE class=prog_in_0> {</PRE><PRE class=prog_in_0> return es;</PRE><PRE class=prog_in_0> }</PRE><PRE class=prog_in_0> if (intType == AcDb::kExtendArg</PRE><PRE class=prog_in_0> || intType == AcDb::kExtendBoth)</PRE><PRE class=prog_in_0> {</PRE><PRE class=prog_in_0> intType = AcDb::kExtendThis;</PRE><PRE class=prog_in_0> }</PRE><PRE class=prog_in_0> AcDbLine *pAcadLine;</PRE><PRE class=prog_in_0></PRE><PRE class=prog_in_0> for (int i = 0; i < vertexArray.length() - 1; i++) {</PRE><PRE class=prog_in_0> pAcadLine = new AcDbLine();</PRE><PRE class=prog_in_0> pAcadLine->setStartPoint(vertexArray);</PRE><PRE class=prog_in_0> pAcadLine->setEndPoint(vertexArray);</PRE><PRE class=prog_in_0> pAcadLine->setNormal(normal());</PRE><PRE class=prog_in_0> if ((es = ent->intersectWith(pAcadLine, intType,</PRE><PRE class=prog_in_0> projPlane, points)) != Acad::eOk)</PRE><PRE class=prog_in_0> {</PRE><PRE class=prog_in_0> delete pAcadLine;</PRE><PRE class=prog_in_0> return es;</PRE><PRE class=prog_in_0> }</PRE><PRE class=prog_in_0> delete pAcadLine;</PRE><PRE class=prog_in_0> }</PRE><PRE class=prog_in_0></PRE><PRE class=prog_in_0> // All the points that we selected in this process are on</PRE><PRE class=prog_in_0> // the other curve; we are dealing with apparent</PRE><PRE class=prog_in_0> // intersection. If the other curve is 3D or is not</PRE><PRE class=prog_in_0> // on the same plane as poly, the points are not on</PRE><PRE class=prog_in_0> // poly.</PRE><PRE class=prog_in_0> // </PRE><PRE class=prog_in_0> // In this case, we need to do some more work. Project the</PRE><PRE class=prog_in_0> // points back onto the plane. They should lie on</PRE><PRE class=prog_in_0> // the projected poly. Find points on real poly</PRE><PRE class=prog_in_0> // corresponding to the projected points.</PRE><PRE class=prog_in_0> //</PRE><PRE class=prog_in_0> AcGePoint3d projPt, planePt;</PRE><PRE class=prog_in_0> AcGePoint3dArray pts;</PRE><PRE class=prog_in_0> AcGeLine3d line;</PRE><PRE class=prog_in_0> </PRE><PRE class=prog_in_0> AcGePlane polyPlane;</PRE><PRE class=prog_in_0> AcDb::Planarity plnrty;</PRE><PRE class=prog_in_0> getPlane(polyPlane,plnrty);</PRE><PRE class=prog_in_0></PRE><PRE class=prog_in_0> for (i = 0; i < points.length(); i++) {</PRE><PRE class=prog_in_0> // Define a line starting from the projPt and</PRE><PRE class=prog_in_0> // along the normal.Intersect the polygon with</PRE><PRE class=prog_in_0> // that line. Find all the points and pick the</PRE><PRE class=prog_in_0> // one closest to the given point.</PRE><PRE class=prog_in_0> //</PRE><PRE class=prog_in_0> projPt = points.orthoProject(projPlane);</PRE><PRE class=prog_in_0> line.set(projPt, projPlane.normal());</PRE><PRE class=prog_in_0></PRE><PRE class=prog_in_0> if ((es = intLine(this, line, pts))</PRE><PRE class=prog_in_0> != Acad::eOk)</PRE><PRE class=prog_in_0> {</PRE><PRE class=prog_in_0> return es;</PRE><PRE class=prog_in_0> }</PRE><PRE class=prog_in_0></PRE><PRE class=prog_in_0> planePt = projPt.project(polyPlane,</PRE><PRE class=prog_in_0> projPlane.normal());</PRE><PRE class=prog_in_0> points = pts;</PRE><PRE class=prog_in_0> double length = (planePt - pts).length();</PRE><PRE class=prog_in_0> double length2;</PRE><PRE class=prog_in_0></PRE><PRE class=prog_in_0> for (int j = 1; j < pts.length(); j++) {</PRE><PRE class=prog_in_0> if ((length2 = (planePt - pts).length())</PRE><PRE class=prog_in_0> < length)</PRE><PRE class=prog_in_0> {</PRE><PRE class=prog_in_0> points = pts;</PRE><PRE class=prog_in_0> length = length2;</PRE><PRE class=prog_in_0> }</PRE><PRE class=prog_in_0> }</PRE><PRE class=prog_in_0> }</PRE><PRE class=prog_in_0> }</PRE><PRE class=prog_in_0> return es;</PRE><PRE class=prog_in_end_0>}</PRE><PRE class=prog_in_end_0> </PRE> <P class=signature style="MARGIN: auto 0cm"><FONT face=宋体 size=3>已知点、线求距离</FONT></P>
<P class=signature style="MARGIN: auto 0cm"><FONT face=宋体 size=3>double length;</FONT></P>
<P class=signature style="MARGIN: auto 0cm"><FONT face=宋体 size=3>AcGePoint2d Pt;</FONT></P>
<P class=signature style="MARGIN: auto 0cm"><FONT size=3><FONT face=宋体>AcGeCurve2d *ent2d;<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></FONT></P>
<P class=signature style="MARGIN: auto 0cm"><FONT size=3><FONT face=宋体>length = ent2d->distanceTo(Pt,AcGeContext::gTol);<o:p></o:p></FONT></FONT></P> <P>我想用<FONT size=3>distanceTo(Pt,AcGeContext::gTol);来计算距离</FONT></P>
<P><FONT size=3>可是我的线,点都是AcDb类型的不能用</FONT></P>
<P><FONT size=3>如何才能将AcDb类型的线,点转化为AcGe类型呢?</FONT></P>
页:
[1]