First commit. Project reactivation.
This commit is contained in:
commit
849d414822
3 changed files with 59 additions and 0 deletions
1
README.txt
Normal file
1
README.txt
Normal file
|
@ -0,0 +1 @@
|
|||
I started this project few months ago. Now I'm going to ressurect it. cookie_generator.py is a script I wrote then. I plan to use the same idea, but implement it in different way.
|
1
README.txt~
Normal file
1
README.txt~
Normal file
|
@ -0,0 +1 @@
|
|||
|
57
cookie_generator.py
Normal file
57
cookie_generator.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
#print "Hello"
|
||||
from __future__ import division
|
||||
from math import sqrt
|
||||
from math import atan
|
||||
|
||||
|
||||
def distance(pos1, pos2):
|
||||
return sqrt(sum([ (x[0] -x[1])**2 for x in zip(pos1, pos2)]))
|
||||
|
||||
def compute_lengths(positions):
|
||||
lengths = []
|
||||
for i in range(len(positions)):
|
||||
if (i < len(positions) -1):
|
||||
lengths.append(distance(positions[i], positions[i+1]))
|
||||
else:
|
||||
lengths.append(distance(positions[i], positions[0]))
|
||||
|
||||
return lengths
|
||||
|
||||
def direction(pos1, pos2):
|
||||
if ((pos1[1] - pos2[1]) != 0):
|
||||
if (atan((pos1[0]-pos2[0])/(pos1[1] - pos2[1]))!= 0):
|
||||
return atan((pos1[0]-pos2[0])/(pos1[1] - pos2[1]))*180/3.1415
|
||||
|
||||
|
||||
def compute_angles(positions):
|
||||
return [direction(x, positions[(i+1)% len(positions)]) for i, x in enumerate(positions)]
|
||||
|
||||
|
||||
def generate_scad_script(positions, angles, lengths):
|
||||
#positions[len(positions) -1] = positions[0]
|
||||
text = ""
|
||||
for element in zip(positions, angles, lengths):
|
||||
text += "translate(" + str(element[0]) + ") "
|
||||
text += "rotate([0, 0," + str(element[1]) +"]) "
|
||||
text += "cube([" + str(element[2]) + ", 2, 6]);\n"
|
||||
|
||||
return text
|
||||
|
||||
|
||||
def main():
|
||||
sample_positions = [
|
||||
[0, 3, 0],
|
||||
[5, 5, 0],
|
||||
[-8, 6, 0]
|
||||
]
|
||||
lengths = compute_lengths(sample_positions)
|
||||
|
||||
angles = compute_angles(sample_positions)
|
||||
print lengths
|
||||
print angles
|
||||
print distance([1, 0, 3], [2, 5, 5])
|
||||
print direction([1, 0, 3], [2, 5, 5])
|
||||
|
||||
print generate_scad_script(sample_positions, angles, lengths )
|
||||
main()
|
||||
|
Loading…
Reference in a new issue