2016-07-15 18:29:14 +02:00
|
|
|
from math import *
|
|
|
|
|
2016-08-17 15:07:41 +02:00
|
|
|
|
2016-07-15 18:29:14 +02:00
|
|
|
def arcOnCircle(spanning_angle, outgoing_angle, r=1.0):
|
2016-08-17 15:07:41 +02:00
|
|
|
angle = spanning_angle + 2 * outgoing_angle
|
|
|
|
radius = r * sin(radians(0.5 * spanning_angle)) / sin(radians(180 - outgoing_angle - 0.5 * spanning_angle))
|
2016-07-15 18:29:14 +02:00
|
|
|
return angle, abs(radius)
|
|
|
|
|
|
|
|
|
2016-08-17 15:07:41 +02:00
|
|
|
class Parts:
|
2016-07-15 18:29:14 +02:00
|
|
|
def __init__(self, boxes):
|
|
|
|
self.boxes = boxes
|
2016-08-17 15:07:41 +02:00
|
|
|
|
2016-07-15 18:29:14 +02:00
|
|
|
"""
|
|
|
|
def roundKnob(self, diameter, n=20, callback=None, move=""):
|
2016-07-17 18:02:51 +02:00
|
|
|
size = diameter+diameter/n
|
2016-07-15 18:29:14 +02:00
|
|
|
if self.move(size, size, move, before=True):
|
|
|
|
return
|
|
|
|
self.moveTo(size/2, size/2)
|
|
|
|
self.cc(callback, None, 0, 0)
|
|
|
|
|
2016-07-17 18:02:51 +02:00
|
|
|
self.move(size, size, move)
|
2016-07-15 18:29:14 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
def __getattr__(self, name):
|
|
|
|
return getattr(self.boxes, name)
|
2016-08-17 15:07:41 +02:00
|
|
|
|
2016-07-17 18:02:51 +02:00
|
|
|
def disc(self, diameter, hole=0, callback=None, move=""):
|
2016-07-27 22:19:32 +02:00
|
|
|
size = diameter
|
2016-08-17 15:07:41 +02:00
|
|
|
r = diameter / 2.0
|
|
|
|
|
2016-07-15 18:29:14 +02:00
|
|
|
if self.move(size, size, move, before=True):
|
|
|
|
return
|
2016-08-17 15:07:41 +02:00
|
|
|
|
|
|
|
self.moveTo(size / 2, size / 2)
|
|
|
|
|
2016-07-17 18:02:51 +02:00
|
|
|
if hole:
|
2016-08-17 15:07:41 +02:00
|
|
|
self.hole(0, 0, hole / 2)
|
|
|
|
|
2016-07-15 18:29:14 +02:00
|
|
|
self.cc(callback, None, 0, 0)
|
2016-08-17 15:07:41 +02:00
|
|
|
self.moveTo(r + self.burn, 0, 90)
|
2016-07-15 18:29:14 +02:00
|
|
|
self.corner(360, r)
|
2016-07-24 22:28:27 +02:00
|
|
|
self.move(size, size, move)
|
2016-08-17 15:07:41 +02:00
|
|
|
|
2016-07-17 18:02:51 +02:00
|
|
|
def waivyKnob(self, diameter, n=20, angle=45, hole=0, callback=None, move=""):
|
2016-08-17 15:07:41 +02:00
|
|
|
size = diameter + pi * diameter / n
|
|
|
|
|
2016-07-15 18:29:14 +02:00
|
|
|
if self.move(size, size, move, before=True):
|
|
|
|
return
|
2016-08-17 15:07:41 +02:00
|
|
|
|
|
|
|
self.moveTo(size / 2, size / 2)
|
2016-07-15 18:29:14 +02:00
|
|
|
self.cc(callback, None, 0, 0)
|
2016-08-17 15:07:41 +02:00
|
|
|
|
2016-07-17 18:02:51 +02:00
|
|
|
if hole:
|
2016-08-17 15:07:41 +02:00
|
|
|
self.hole(0, 0, hole / 2)
|
|
|
|
|
|
|
|
self.moveTo(diameter / 2, 0, angle)
|
|
|
|
a, r = arcOnCircle(360. / n, angle, diameter / 2)
|
|
|
|
a2, r2 = arcOnCircle(360. / n, -angle, diameter / 2)
|
|
|
|
|
|
|
|
for i in range(n // 2):
|
2016-07-15 18:29:14 +02:00
|
|
|
self.boxes.corner(a, r)
|
|
|
|
self.boxes.corner(a2, r2)
|
2016-08-17 15:07:41 +02:00
|
|
|
|
2016-07-17 18:02:51 +02:00
|
|
|
self.move(size, size, move)
|
2016-07-15 18:29:14 +02:00
|
|
|
|
2016-07-17 18:02:51 +02:00
|
|
|
def concaveKnob(self, diameter, n=3, rounded=0.2, angle=70, hole=0,
|
|
|
|
callback=None, move=""):
|
2016-07-27 22:19:32 +02:00
|
|
|
size = diameter
|
2016-08-17 15:07:41 +02:00
|
|
|
|
2016-07-15 18:29:14 +02:00
|
|
|
if self.move(size, size, move, before=True):
|
|
|
|
return
|
2016-08-17 15:07:41 +02:00
|
|
|
|
|
|
|
self.moveTo(size / 2, size / 2)
|
|
|
|
|
2016-07-17 18:02:51 +02:00
|
|
|
if hole:
|
2016-08-17 15:07:41 +02:00
|
|
|
self.hole(0, 0, hole / 2)
|
|
|
|
|
2016-07-15 18:29:14 +02:00
|
|
|
self.cc(callback, None, 0, 0)
|
2016-08-17 15:07:41 +02:00
|
|
|
self.moveTo(diameter / 2, 0, 90 + angle)
|
|
|
|
a, r = arcOnCircle(360. / n * (1 - rounded), -angle, diameter / 2)
|
|
|
|
|
|
|
|
if abs(a) < 0.01: # avoid trying to make a straight line as an arc
|
|
|
|
a, r = arcOnCircle(360. / n * (1 - rounded), -angle - 0.01, diameter / 2)
|
|
|
|
|
2016-07-15 18:29:14 +02:00
|
|
|
for i in range(n):
|
|
|
|
self.boxes.corner(a, r)
|
|
|
|
self.corner(angle)
|
2016-08-17 15:07:41 +02:00
|
|
|
self.corner(360. / n * rounded, diameter / 2)
|
2016-07-15 18:29:14 +02:00
|
|
|
self.corner(angle)
|
2016-07-27 22:19:32 +02:00
|
|
|
|
2016-07-17 18:02:51 +02:00
|
|
|
self.move(size, size, move)
|