icesword 发表于 2007-8-16 23:23:00

VBA中如何得到一条直线与球体的交点坐标

<p>请问大虾:VBA中如何得到一条直线与球体的交点坐标?</p><p>我用AutoCAD给的例子:</p><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) = -13: startPt(1) = 1: startPt(2) = 0<br/>&nbsp;&nbsp;&nbsp; endPt(0) = 12: endPt(1) = 5: endPt(2) = 0<br/>&nbsp;&nbsp;&nbsp; Set lineObj = ThisDrawing.ModelSpace.AddLine(startPt, endPt)<br/>&nbsp; </p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Dim sphereObj As Acad3DSolid<br/>&nbsp;&nbsp;&nbsp; Dim centerPoint(0 To 2) As Double<br/>&nbsp;&nbsp;&nbsp; Dim radius As Double<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; centerPoint(0) = 0#: centerPoint(1) = 0#: centerPoint(2) = 0#<br/>&nbsp;&nbsp;&nbsp; radius = 10#<br/>&nbsp;&nbsp;&nbsp; Set sphereObj = ThisDrawing.ModelSpace.AddSphere(centerPoint, radius)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <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(sphereObj, 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><p>该怎么解决啊?急!!!</p>
页: [1]
查看完整版本: VBA中如何得到一条直线与球体的交点坐标