Skip to content

Instantly share code, notes, and snippets.

@debuti
Created March 24, 2024 22:16
Show Gist options
  • Select an option

  • Save debuti/a8e43b8e017d19e8e1a577162a25b1c5 to your computer and use it in GitHub Desktop.

Select an option

Save debuti/a8e43b8e017d19e8e1a577162a25b1c5 to your computer and use it in GitHub Desktop.

Revisions

  1. debuti created this gist Mar 24, 2024.
    34 changes: 34 additions & 0 deletions parametric-archimedean-spiral
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    #!/usr/local/bin/python3

    import argparse
    from math import *
    from dxfwrite import DXFEngine as dxf

    parser = argparse.ArgumentParser(description='Generate Vogel Spiral ps file')

    parser.add_argument('-p', dest='points', type=int, action='store', help='the number of points to plot', default=100)
    parser.add_argument('-s', dest='radius_start', type=int, action='store', help='the radius starting length', default=0)
    parser.add_argument('-r', dest='radius_delta', type=float, action='store', help='the radius incr between two adjacent points', default=1)
    parser.add_argument('-t', dest='theta_delta', type=float, action='store', help='the theta incr between two adjacent points', default=2*pi/360)
    parser.add_argument('-f', dest='file', action='store', help='the ps file to write')
    args = parser.parse_args()

    print(f"Printing spiral into {args.file} with deltas: r={args.radius_delta}, t={args.theta_delta:06.4f}")

    drawing = dxf.drawing(args.file)
    # set unit of measurement to mm
    drawing.header['$LUNITS'] = 4

    vertices = []
    r = args.radius_start
    theta = 0
    for _ in range(args.points):
    r += args.radius_delta
    theta += args.theta_delta

    vertices.append((cos(theta)*r, sin(theta)*r))

    polyline= dxf.polyline(linetype='DOT')
    polyline.add_vertices(vertices)
    drawing.add(polyline)
    drawing.save()