fengxue007 发表于 2008-6-12 22:55:00

求助:怎么求两条相交多段线的交点?

怎么求两条相交多段线的交点?谢谢!

robbin840311 发表于 2008-6-13 08:23:00

<p>请看VBA帮助中的IntersectWith方法。</p><p>语法如下:</p><p class="Heading-2"><strong>Signature</strong>
        </p><p class="syntax">RetVal = object.IntersectWith(IntersectObject, ExtendOption) </p><p class="element"><strong>Object</strong></p><p class="element-desc"><a href="mk:@MSITStore:C:\Program%20Files\Common%20Files\Autodesk%20Shared\ACADAUTO.CHM::/all_drawing_objects.htm">All Drawing Objects</a> (Except Pviewport and PolygonMesh)<br/>The object or objects this method applies to. </p><p class="element"><strong>IntersectObject</strong></p><p class="element-desc">Object, input-only; <br/>The object can be one of <a href="mk:@MSITStore:C:\Program%20Files\Common%20Files\Autodesk%20Shared\ACADAUTO.CHM::/all_drawing_objects.htm">All Drawing Objects</a>.<br/></p><p class="element"><strong>ExtendOption</strong></p><p class="element-desc">AcExtendOption enum; input-only<br/>This option specifies if none, one or both, of the objects are to be extended in order to attempt an intersection.</p><p><table class="Simple"><tbody><tr valign="top"><td><p class="constant">acExtendNone</p></td><td><p class="constant-desc">Does not extend either object.</p></td></tr><tr valign="top"><td><p class="constant">acExtendThisEntity</p></td><td><p class="constant-desc">Extends the base object.</p></td></tr><tr valign="top"><td><p class="constant">acExtendOtherEntity</p></td><td><p class="constant-desc">Extends the object passed as an argument.</p></td></tr><tr valign="top"><td><p class="constant">acExtendBoth</p></td><td><p class="constant-desc">Extends both objects.</p></td></tr></tbody></table></p><p class="element"><strong>RetVal&nbsp;&nbsp; 这就是获取的交点坐标</strong></p><p class="element-desc">Variant (array of doubles)<br/>The array of points where one object intersects another object in the drawing</p><p>如VBA自带的例子:</p><pre class="Code">Sub Example_IntersectWith()
    ' This example creates a line and circle and finds the points at
    ' which they intersect.
   
    ' Create the line
    Dim lineObj As AcadLine
    Dim startPt(0 To 2) As Double
    Dim endPt(0 To 2) As Double
    startPt(0) = 1: startPt(1) = 1: startPt(2) = 0
    endPt(0) = 5: endPt(1) = 5: endPt(2) = 0
    Set lineObj = ThisDrawing.ModelSpace.AddLine(startPt, endPt)
      
    ' Create the circle
    Dim circleObj As AcadCircle
    Dim centerPt(0 To 2) As Double
    Dim radius As Double
    centerPt(0) = 3: centerPt(1) = 3: centerPt(2) = 0
    radius = 1
    Set circleObj = ThisDrawing.ModelSpace.AddCircle(centerPt, radius)
    ZoomAll
      
    ' Find the intersection points between the line and the circle
    Dim intPoints As Variant
    intPoints = lineObj.IntersectWith(circleObj, acExtendNone)
   
    ' Print all the intersection points
    Dim I As Integer, j As Integer, k As Integer
    Dim str As String
    If VarType(intPoints) &lt;&gt; vbEmpty Then
      For I = LBound(intPoints) To UBound(intPoints)
            str = "Intersection Point[" &amp; k &amp; "] is: " &amp; intPoints(j) &amp; "," &amp; intPoints(j + 1) &amp; "," &amp; intPoints(j + 2)
            MsgBox str, , "IntersectWith Example"
            str = ""
            I = I + 2
            j = j + 3
            k = k + 1
      Next
    End If
End Sub</pre>

robbin840311 发表于 2008-6-13 08:24:00

<p>请查看VBA中的IntersectWith方法。</p><p></p>
页: [1]
查看完整版本: 求助:怎么求两条相交多段线的交点?