sdaulj 发表于 2009-11-15 19:01:00

在实体相交判断中的问题

<p>请教高手,实体有无交点能不能判断?应该怎么判断?</p><p>能不能用IntersectWith命令判断?</p><p>请高手指点</p><p>如果不能的话有没有办法自己编程实现?</p>

home 发表于 2009-11-16 09:00:00

<p>Sub Example_IntersectWith()<br/>&nbsp;&nbsp;&nbsp; ' This example creates a line and circle and finds the points at<br/>&nbsp;&nbsp;&nbsp; ' which they intersect.<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' Create the line<br/>&nbsp;&nbsp;&nbsp; Dim lineObj As AcadLine<br/>&nbsp;&nbsp;&nbsp; Dim startPt(0 To 2) As Double<br/>&nbsp;&nbsp;&nbsp; Dim endPt(0 To 2) As Double<br/>&nbsp;&nbsp;&nbsp; startPt(0) = 1: startPt(1) = 1: startPt(2) = 0<br/>&nbsp;&nbsp;&nbsp; endPt(0) = 5: endPt(1) = 5: endPt(2) = 0<br/>&nbsp;&nbsp;&nbsp; Set lineObj = ThisDrawing.ModelSpace.AddLine(startPt, endPt)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' Create the circle<br/>&nbsp;&nbsp;&nbsp; Dim circleObj As AcadCircle<br/>&nbsp;&nbsp;&nbsp; Dim centerPt(0 To 2) As Double<br/>&nbsp;&nbsp;&nbsp; Dim radius As Double<br/>&nbsp;&nbsp;&nbsp; centerPt(0) = 8: centerPt(1) = 8: centerPt(2) = 0<br/>&nbsp;&nbsp;&nbsp; radius = 1<br/>&nbsp;&nbsp;&nbsp; Set circleObj = ThisDrawing.ModelSpace.AddCircle(centerPt, radius)<br/>&nbsp;&nbsp;&nbsp; ZoomAll<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' Find the intersection points between the line and the circle<br/>&nbsp;&nbsp;&nbsp; Dim intPoints As Variant<br/>&nbsp;&nbsp;&nbsp; intPoints = lineObj.IntersectWith(circleObj, acExtendNone)<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' Print all the intersection points<br/>&nbsp;&nbsp;&nbsp; Dim I As Integer, j As Integer, k As Integer<br/>&nbsp;&nbsp;&nbsp; Dim str As String<br/>&nbsp;&nbsp;&nbsp; If VarType(intPoints) &lt;&gt; vbEmpty Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For I = LBound(intPoints) To UBound(intPoints)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; str = "Intersection Point[" &amp; k &amp; "] is: " &amp; intPoints(j) &amp; "," &amp; intPoints(j + 1) &amp; "," &amp; intPoints(j + 2)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox str, , "IntersectWith Example"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; str = ""<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I = I + 2<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; j = j + 3<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; k = k + 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<br/>&nbsp;&nbsp;&nbsp; End If<br/>End Sub</p><p></p><p>这个例子中,通过判断数组是否为空,来看看是否有交点!</p>

sdaulj 发表于 2009-11-17 19:41:00

有没有实体相交判断的例子
页: [1]
查看完整版本: 在实体相交判断中的问题