Created
March 24, 2024 22:16
-
-
Save debuti/a8e43b8e017d19e8e1a577162a25b1c5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment