Last active
March 15, 2019 16:08
-
-
Save kogcyc/021ad3f664029d5bf0538792c2903b2e to your computer and use it in GitHub Desktop.
a Python bit that creates the shape of the spline for a 'standard' Shimano freehub cassette body
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
from math import cos,sin,atan,radians | |
import os | |
class Pt(): | |
def __init__(self,x=0,y=0): | |
self.x = x | |
self.y = y | |
def rotate(self,about,a,returnInts=False): | |
ax = about.x | |
ay = about.y | |
rads = radians(a) | |
cosa = cos(rads) | |
sina = sin(rads) | |
rx = ax + cosa * (self.x - ax) - sina * (self.y - ay) | |
ry = ay + sina * (self.x - ax) + cosa * (self.y - ay) | |
return(self.returnPt(rx,ry,returnInts)) | |
def trans(self,transPt,returnInts=False): | |
tx = self.x + transPt.x | |
ty = self.y + transPt.y | |
return(self.returnPt(tx,ty,returnInts)) | |
def rect(self,len,a,returnInts=False): | |
dx = self.x + len * cos(radians(a)) | |
dy = self.y - len * sin(radians(a)) | |
return(self.returnPt(dx,-dy,returnInts)) | |
def cs(self,b,c): | |
f = cos(atan(b/c)) | |
x = self.x + round(f * c) | |
y = self.y + b | |
return Pt(x,y) | |
def couplet(self): | |
return(f'{round(self.x,2)},{round(self.y,2)}') | |
@staticmethod | |
def returnPt(x,y,returnInts): | |
if returnInts: | |
return(Pt(round(x),round(y))) | |
else: | |
return(Pt(x,y)) | |
a = 40.0 | |
r = 280 | |
s = 18 | |
a1 = 22 | |
a2 = 182 | |
pz = Pt(r,0) | |
p1 = pz.rotate(Pt(),-20) | |
#p2 = p1.rect(s,a1) | |
p2 = Pt(p1.x-17,p1.y+11) | |
p4 = pz | |
#p3 = p4.rect(s,a2) | |
p3 = Pt(p4.x-19,p4.y-3) | |
p5 = p4.rotate(Pt(),20) | |
path = "" | |
for t in range(9): | |
if t == 0: | |
cmd = 'M' | |
else: | |
cmd = 'L' | |
p1r = p1.rotate(Pt(),a*t) | |
p2r = p2.rotate(Pt(),a*t) | |
p3r = p3.rotate(Pt(),a*t) | |
p4r = p4.rotate(Pt(),a*t) | |
p5r = p5.rotate(Pt(),a*t) | |
path = path + f'{cmd}{round(p1r.x)},{round(p1r.y*-1)} ' | |
path = path + f'L{round(p2r.x)},{round(p2r.y*-1)} ' | |
path = path + f'L{round(p3r.x)},{round(p3r.y*-1)} ' | |
path = path + f'L{round(p4r.x)},{round(p4r.y*-1)} ' | |
path = path + f'A 280,280 0 0 0 {round(p5r.x)},{round(p5r.y*-1)} ' | |
path = path + '\n' | |
svg = f''' | |
<svg width="800" height="800"> | |
<rect width="800" height="800" style="fill:#ccc; "/> | |
<g transform="translate(400,400)"> | |
<path | |
style= "fill:rgb(33,33,33); stroke-width:0px; stroke:#f00;" | |
d="{path} Z"/> | |
</g> | |
</svg> | |
''' | |
print(svg) | |
fp = open('thurs.svg','w') | |
fp.write(svg) | |
fp.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment