Home > RhinoScript, Tutorials > Creating Archimedean Spirals

Creating Archimedean Spirals

image

Url:
Rhino Wiki
Summary:
Demonstrates how to create Archimedean Spirals using RhinoScript. (Rhino 4.0)
Answer:
In polar coordinates (r, Θ), an Archimedean Spiral can be described by the following equation:
r = a + bΘ
with real numbers a and b. Changing the parameter a will turn the spiral, while b controls the distance between successive turnings.

Once the polar coordinates have been calculated, we can use RhinoScript’s Polar method to convert them to Cartesian coordinates, which will allow us to plot the curve using RhinoScript’s AddInterpCurve method.

The following sample script code demonstrates how to create an interpolated curve through the points that were calculated using the above equation:

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  ' ArchimedeanSpiral.rvb -- June 2008
  ' If this code works, it was written by Dale Fugier.
  ' If not, I don't know who wrote it.
  ' Works with Rhino 4.0.

  Option Explicit

  Sub ArchimedeanSpiral()

    Dim a_const, b_const, step_angle, num_points
    Dim curr_angle, base_point, radius, points(), i

    Rhino.Print "Archimedean Spiral (r = a + bΘ)"

    a_const = Rhino.GetReal("Value of 'A' constant", 1.0, 0.01)
    If IsNull(a_const) Then Exit Sub

    b_const = Rhino.GetReal("Value of 'B' constant", 1.0, 0.01)
    If IsNull(a_const) Then Exit Sub

    num_points = Rhino.GetInteger("Number of points to calculate", 10, 2)
    If IsNull(num_points) Then Exit Sub

    step_angle = Rhino.GetReal("Angle between points", 30.0, 1.0, 45.0)
    If IsNull(step_angle) Then Exit Sub

    curr_angle = 0.0
    base_point = Array(0.0, 0.0, 0.0)
    ReDim points(num_points - 1)

    For i = 0 To UBound(points)
      radius = a_const + (b_const * curr_angle)
      points(i) = Rhino.Polar(base_point, radius, curr_angle)
      curr_angle = curr_angle + step_angle
    Next

    Rhino.AddInterpCurve points
    'Rhino.AddPoints points

  End Sub
  1. Lincoln
    October 21st, 2009 at 04:47 | #1

    Actually there are some problems with this script:

    1. It doesn’t run unless you add a call to the subroutine, as in

    Call ArchimedeanSpiral()
    Sub ArchimedeanSpiral()
    ….

    2. The Rhino.polar function has parameters given in the wrong order (angle comes before radius).

    Change: points(i) = Rhino.Polar(base_point, radius, curr_angle)
    to: points(i) = Rhino.Polar(base_point, curr_angle, radius)

    • nnnaaarrr
      October 28th, 2009 at 12:46 | #2

      :) I am very grateful to you for your reply.

  1. No trackbacks yet.