VBA中如何得到一条直线与球体的交点坐标
<p>请问大虾:VBA中如何得到一条直线与球体的交点坐标?</p><p>我用AutoCAD给的例子:</p><p>Sub Example_IntersectWith()<br/> ' This example creates a line and circle and finds the points at<br/> ' which they intersect.<br/> <br/> ' Create the line<br/> Dim lineObj As AcadLine<br/> Dim startPt(0 To 2) As Double<br/> Dim endPt(0 To 2) As Double<br/> startPt(0) = -13: startPt(1) = 1: startPt(2) = 0<br/> endPt(0) = 12: endPt(1) = 5: endPt(2) = 0<br/> Set lineObj = ThisDrawing.ModelSpace.AddLine(startPt, endPt)<br/> </p><p> <br/> Dim sphereObj As Acad3DSolid<br/> Dim centerPoint(0 To 2) As Double<br/> Dim radius As Double<br/> <br/> centerPoint(0) = 0#: centerPoint(1) = 0#: centerPoint(2) = 0#<br/> radius = 10#<br/> Set sphereObj = ThisDrawing.ModelSpace.AddSphere(centerPoint, radius)<br/> <br/> <br/> ' Find the intersection points between the line and the circle<br/> Dim intPoints As Variant<br/> intPoints = lineObj.IntersectWith(sphereObj, acExtendNone)<br/> <br/> ' Print all the intersection points<br/> Dim I As Integer, j As Integer, k As Integer<br/> Dim str As String<br/> If VarType(intPoints) <> vbEmpty Then<br/> For I = LBound(intPoints) To UBound(intPoints)<br/> str = "Intersection Point[" & k & "] is: " & intPoints(j) & "," & intPoints(j + 1) & "," & intPoints(j + 2)<br/> MsgBox str, , "IntersectWith Example"<br/> str = ""<br/> I = I + 2<br/> j = j + 3<br/> k = k + 1<br/> Next<br/> End If<br/>End Sub</p><p>总是出现下面的错误:</p><p></p><p>该怎么解决啊?急!!!</p>
页:
[1]