tiancao1001 于 2008-10-13 02:55 PM 发表评论: |
Private Sub CommandButton2_Click() Dim i As Long Dim N As Integer Dim Pi As Double Pi = 4# * Atn(1#) Dim R As Long Randomize R = Int(Rnd * 100) Dim R1 As Long R1 = (0.5 - Rnd) * 199 Dim L As Long L = Int(Rnd * 100) Dim S As Long S = Int(Rnd * 50) Dim m As Long m = Int(Rnd * 100) Dim A1 As Double Dim A2 As Double Dim P(2) As Double Dim P0(2) As Double Dim X As Double Dim Y As Double Dim Fit() As Double Dim Sp As AcadSpline ReDim Fit(2) i = i + 1 A1 = i * Pi / 180 A2 = (R1 / R) * A1 X = (-(R1 - R) * Cos(A1) - S * Cos(A2 - A1) + 100) * m Y = ((R1 - R) * Sin(A1) - S * Sin(A2 - A1) + 100) * m P0(0) = X: P0(1) = Y Fit(0) = X: Fit(1) = Y: Fit(2) = 0 'ThisDrawing.ModelSpace.AddPoint P0 Do DoEvents i = i + 1 N = N + 1 ReDim Preserve Fit((N + 1) * 3 - 1) '跳过第一个点,因为该点已经等于上一条曲线的最后一个点了。 A1 = i * Pi / 180 A2 = (R1 / R) * A1 X = (-(R1 - R) * Cos(A1) - S * Cos(A2 - A1) + 100) * m Y = ((R1 - R) * Sin(A1) - S * Sin(A2 - A1) + 100) * m P(0) = X: P(1) = Y Fit((N + 1) * 3 - 3) = X: Fit((N + 1) * 3 - 2) = Y: Fit((N + 1) * 3 - 1) = 0 If N = 360 Then '绘制样条曲线,起点和终点的切线方向为前两个点的矢量方向和最后两个点的矢量方向 Set Sp = ThisDrawing.ModelSpace.AddSpline(Fit, Point3D(Fit(3) - Fit(0), Fit(4) - Fit(1), 0), Point3D(Fit(1077) - Fit(1074), Fit(1078) - Fit(1075), 0)) Randomize 'Sp.color = Int(Rnd * 255) N = 0 Fit(0) = Fit(1077): Fit(1) = Fit(1078): Fit(2) = 0 '然第一点等于最后一个点,这样样条曲线才能收尾相接 End If If Abs(P(0) - P0(0)) < 10 ^ -2 And Abs(P(1) - P0(1)) < 10 ^ -2 Then Exit Do 'If i > 10 ^ 4 Then Exit Do Loop MsgBox "R=" & R & "/ R1=" & R1 & "/ L=" & L Prompt "R=" & R & "/ R1=" & R1 & "/ L=" & L & "/ S=" & S & vbCrLf End End Sub |
|
查看所评论的日志:CAD VBA 也能画出这样的样条曲线spirograph万花尺螺旋曲线 |
tiancao1001 于 2008-10-10 05:58 PM 发表评论: |
|
查看所评论的日志:田草日志 |
tiancao1001 于 2008-10-10 04:22 PM 发表评论: |
|
查看所评论的日志:田草日志 |
tiancao1001 于 2008-10-08 10:56 PM 发表评论: |
|
查看所评论的日志:田草日志 |
tiancao1001 于 2008-10-08 10:44 PM 发表评论: |
|
查看所评论的日志:田草日志 |
tiancao1001 于 2008-09-22 05:38 PM 发表评论: |
<iframe allowTransparency=true src='http://weather.cn.yahoo.com/cframe.html' scrolling=no border=0 frameborder=0 marginwidth=1 marginheight=1 height='80' width='120'></iframe> |
|
查看所评论的日志:yahoo天气预报 |
tiancao1001 于 2008-09-21 09:45 PM 发表评论: |
|
查看所评论的日志:田草日志 |
tiancao1001 于 2008-09-21 09:44 PM 发表评论: |
|
查看所评论的日志:田草日志 |