I am a bit stuck.
I am trying to calculate the distance to move gears of different sizes so they align next to each other. I think its some sort of recursive call, but I can't figure out how to write it. I have a list of radii in the order of the gears
radiusList=[6,16,14,20,24,28]
so the 1st gear = movement distance = 0
2nd gear movement distance = 0 + 6 + 16
3rd gear=0 +6 + 16 +16 + 14
4th gear = 0 +6 + 16 + 16 + 14 + 14 + 20
5th gear = 0 +6 + 16 + 16 + 14 + 14 + 20, +20 ,+ 24
6th gear = 0 +6 + 16 + 16 + 14 + 14 + 20, +20 ,+ 24 + 24 +28 etc...
The other thing is I need it to update - now matter on the radius size, and the number of gears. But can't get my head around how to approach it.
Any help would be greatly appreciated. Thank you.
UPDATE : Thanks everyone, I wrote something like this in the end. Sees a bit long winded though.
def createmovesequence():
if numberofcogs == 0 :
void
if numberofcogs == 1:
newmovelist.append(0)
if numberofcogs == 2:
newmovelist.append(0)
newmovelist.append(radiusList[0])
newmovelist.append(radiusList[1])
if numberofcogs >= 3:
newmovelist.append(0)
newmovelist.append(radiusList[0])
#newmovelist.append(radiusList[1])
for i in range(2, len(radiusList)):
newmovelist.append(radiusList[i-1])
newmovelist.append(radiusList[i-1])
newmovelist.append(radiusList[-1])
# elif numberofcogs != len(radiusList):
# print 'error'
print newmovelist
createmovesequence()
My only other idea was something along the lines of a for loop with lot of if statements...