heimj 发表于 2007-4-30 10:15:00

[求助]如何将一系列的点(X i, Yi)拟合并连接成一条光滑的线?

本帖最后由 作者 于 2007-5-5 9:25:58 编辑 <br /><br /> <p>有一系列的点(X i, Yi) (i=1 ,2 .........N),我用line连接每一点,成了N-1条线,用spline 连接,每次只能连接3个点,成了多线段,</p><p>请问:如何连接成<font color="#ff0000">一条光滑的曲线</font>?(<font color="#ff0000">用vb在CAD中实现</font>)</p><p>谢谢!!!</p>

fjfhgdwfn 发表于 2007-4-30 10:38:00

Public WithEvents PLine As AcadLWPolyline&nbsp;&nbsp;&nbsp; ' Use with Modified Event Example<br/><pre class="Code">Sub Example_Modified()
   ' This example creates a lightweight polyline in model space and
   ' references the PolyLine using the public variable (PLine) which
   ' is set up to intercept Modified events.
   '
   ' This example then modifies the new object, triggering the code
   ' in the Modified event.
   
    Dim points(0 To 9) As Double
   
    ' Define the 2D polyline points
    points(0) = 1: points(1) = 1
    points(2) = 1: points(3) = 2
    points(4) = 2: points(5) = 2
    points(6) = 3: points(7) = 2
    points(8) = 4: points(9) = 4
      
    ' Create a lightweight Polyline object in model space
    '
    ' * Note: We are returning the new PolyLine object into a Module
    ' level variable.This allows us to intercept events associated
    ' with that particular object.
    Set PLine = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
   
    ThisDrawing.Application.ZoomAll
   
    ' Modify object to trigger event.
    '
    ' * Note: The event code for the PolyLine modification will be triggered
    ' before we move forward and refresh the view, so the line will not
    ' appear blue when the event message box is displayed.
    Dim color As AcadAcCmColor
    Set color = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor.16")
    Call color.SetRGB(80, 100, 244)
    PLine.TrueColor = color

    ThisDrawing.Regen acAllViewports
   
End Sub</pre><br/><br/><pre class="Code">Private Sub PLine_Modified(ByVal pObject As AutoCAD.IAcadObject)
    ' This example intercepts an object's Modified event.
    '
    ' This event is triggered when an object supporting this event is modified.
    '
    ' To trigger this code: Modify an object connected to this event
    ' * Note: By connected, we mean the object set up to intercept events using
    ' the VBA WithEvents statement

    ' Use the "pObject" variable to determine which object was modified
    MsgBox "You just modified an object with an ID of: " &amp; pObject.ObjectID
   
End Sub</pre>

heimj 发表于 2007-4-30 11:17:00

<p>谢谢!</p><p>我试试看。</p>

heimj 发表于 2007-4-30 16:17:00

连接的是多边形啊,我要的是曲线,不知道能否实现?

heimj 发表于 2007-5-5 09:28:00

请有知道的高手赐教,谢谢!!!

licong 发表于 2007-5-15 09:34:00

<p>RetVal = object.AddSpline(PointsArray, StartTangent, EndTangent)</p><p>用这个行不行呀</p>

laoliu09 发表于 2007-5-15 19:16:00

样条曲线!

licong 发表于 2007-5-16 09:13:00

<p>嗯,样条曲线可以!主要是StartTangent、 EndTangent这两个参数的设置,在这两个参数中的三个元素是不是第一个是对于X轴的tangent,第二个参数是关于Y轴的tangent,第三个参数是关于Z轴的tangent.</p><p>我做了一个桥型曲线,效果还可以</p><p>Sub drawspline()<br/>Dim x As AcadSpline<br/>Dim pt(1 To 75) As Double<br/>Dim xlapp As Excel.Application<br/>Dim xlbook As Workbook<br/>Dim xlsheet As Worksheet<br/>Dim startangent(0 To 2) As Double<br/>Dim endtangent(0 To 2) As Double<br/>startangent(0) = 0<br/>startangent(1) = 0<br/>startangent(2) = 0<br/>endtangent(0) = 0<br/>endtangent(1) = 0<br/>endtangent(2) = 0<br/>Set xlsApp = New Excel.Application<br/>Set xlbook = xlsApp.Workbooks.Open("F:\CAD练习\book1.xls")<br/>Set xlsheet = xlbook.Worksheets("sheet1")<br/>For i = 1 To 75 Step 3<br/>&nbsp;&nbsp; With xlsheet<br/>&nbsp;&nbsp; pt(i) = .Cells(i, 1)<br/>&nbsp;&nbsp; pt(i + 1) = .Cells(i, 2)<br/>&nbsp;&nbsp; pt(i + 2) = .Cells(i, 3)<br/>&nbsp;&nbsp; End With<br/>&nbsp;&nbsp; <br/>Next i<br/>Set x = ThisDrawing.ModelSpace.AddSpline(pt, startangent, endtangent)</p><p>End Sub</p>

heimj 发表于 2007-5-16 10:00:00

<p>谢谢你们!</p><p>我试试看。</p>

heimj 发表于 2007-5-16 11:14:00

<p>我刚试过了,是一条光滑的曲线,但在所有点画完后,又与原点连接了,这是怎么回事?请问怎样解决?</p><p>谢谢!!!</p>
页: [1]
查看完整版本: [求助]如何将一系列的点(X i, Yi)拟合并连接成一条光滑的线?