Spirals are drawn as either individual lines or a connected polyline. A polyline in autocad vba requires an array of points in the form (x1,y1,x2,y2,x3…). This is constructed with a loop that runs once for each point and adds an x and y value to an array each time through the loop. The polyline is drawn outside the loop with a single statement.
The spiral consisting of individual lines is drawn with a loop that runs once for each line. It stores values for two points x1,y1 and x2,y2 each time through the loop. It draws one line segment inside the loop each time through.
The fermat spiral is sometimes used to draw plant simulations using a bit of geometry at each node rather than a straight line. Instead of calling the line subroutine, any other geometry can be called inside the loop. These are sometimes called daisies or sunflowers.
Sub fermat_spiral_daisy1() 'R = B A^1/2 Call init_polar Dim B As Double, C As Double Dim i As Integer Dim numlines As Integer Dim R1 As Double, R2 As Double Dim A1 As Integer, A2 As Integer Dim A1_rad As Double, A2_rad As Double Dim X1 As Double, X2 As Double Dim Y1 As Double, Y2 As Double B = frm_polar.txt_b8.Value C = 0.5 numlines = (Amax - Amin) / A_inc 'num of lines For i = 1 To numlines A1 = Amin + ((i - 1) * A_inc) A2 = Amin + (i * A_inc) A1_rad = deg2rad(A1) A2_rad = deg2rad(A2) 'this is the function R1 = B * (A1_rad ^ C) R2 = B * (A2_rad ^ C) X1 = R1 * Cos(A1_rad) Y1 = R1 * Sin(A1_rad) X2 = R2 * Cos(A2_rad) Y2 = R2 * Sin(A2_rad) 'this would be the regular spiral 'Call line(X1, Y1, X2, Y2) Call polygon3(R2, A2) Next i Update End Sub Sub polygon3(R As Double, A As Integer) Call connect_acad Dim X As Double, Y As Double Dim plineobj As AcadLWPolyline Dim pt() As Double Dim t As Integer, numpts As Integer numpts = 7 ReDim pt(1 To numpts * 2) 'to store both x and y for one pt Dim AA As Double Dim RR As Integer RR = 3 For t = 1 To 7 AA = 2 * pi * t / 6 + deg2rad(A) X = RR * Cos(AA) + R * Cos(A) Y = RR * Sin(AA) + R * Sin(A) pt(t * 2 - 1) = X: pt(t * 2) = Y Next t Set plineobj = acadApp.ActiveDocument.ModelSpace.AddLightWeightPolyline(pt) plineobj.Closed = True Update End Sub