User:MichaelFrey/Internal Geneva Wheel Builder Feb2024

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Source Code[edit]

mechanism.scad[edit]

use <../../animation/arrow_quad.scad>;

$fn = 50;

n=4;

pinRadius = 1;
r=5;
showInput = true;
showOutput = true;
showOutputHoles =true;
showSupport = true;
showUglySupport = false;
volume =true;
arrows = true;
gap = 0.1;

opacity = 1; //[0:0.1:1]
inputShaftLength = 4;

ang = $t*360;

l2 = 1/tan(180/n)*r;
l3 = pow(l2*l2+r*r,0.5);

outputDiscRadius =l3+r+pinRadius*4;
arrowRadius = l3+r;

slotAngle = 360 / n;

slotLength = r+r*2^0.5;

module circleSeg(r1,r2,ang){
    points1 = [for(i=[0:+ang/10:ang]) [r1*sin(i),r1*cos(i)]];
    points2 = [for(i=[ang:-ang/10:0]) [r2*sin(i),r2*cos(i)]];

    points = [each points1, each points2];
    polygon(points);
}

module arrow_quad(){
    ratio = 2;
    r0 = 3;
    r1 = r0-pinRadius/4;
    r2 = r0+pinRadius/4;
    r3 = r0;
    headArc =30;

    circleSeg(r1,r2,90-headArc);

  //Arrow Head
    i=90;
   point1 = [(r3+pinRadius/ratio)*sin(i-headArc),(r3+pinRadius/ratio)*cos(i-headArc)];
   point2 = [(r3-pinRadius/ratio)*sin(i-headArc),(r3-pinRadius/ratio)*cos(i-headArc)];
   point3 = [r3*sin(i),r3*cos(i)];

  points = [ point1,  point2, point3];
  polygon(points);
}

module slot(ang){
    hull(){
        translate([l2,0,0])
        circle(pinRadius);
        translate([l3+r,0,0])
        circle(pinRadius);
    }

    translate([l2,r])
    rotate([0,0,180])
    circleSeg(r-pinRadius,r+pinRadius,180-ang);
}

module slots(n){
    ang = 360/n;
    for(i=[1:1:n]){
        rotate([0,0,ang*i])
        linear_extrude(height=1)
        slot(ang);
    }
}

module input(){
    a= 1/tan(360/n/2)*r;

    translate([r,a,0])
    rotate([0,0,$t*360])
    translate([0,0,-1.1])
    {
        translate([0,0,-3])rotate([180,0,0])
        if(arrows){
        linear_extrude(height=1)
        {
            arrow_quad();
            rotate([0,0,180])
            arrow_quad();
        }
    }

        color("red",opacity)
        translate([0,0,-inputShaftLength+gap*2])
        cylinder(h=inputShaftLength, r=pinRadius, $fn=6);
        color([1,0.5,0.5],opacity)
        translate([0,0,gap/2])
        hull(){
            cylinder(h=1-gap, r=pinRadius-gap);
                translate([r,0,0])
            cylinder(h=1-gap, r=pinRadius-gap);
        }
        
        translate([r,0,0])
        color("red",opacity)
        cylinder(h=2, r=pinRadius);
    }
}
outfn = n*6;

module outputArrow(turning){
    headArc =slotAngle/8;  
   
    angus = atan2(-a,-r) + slotAngle/4 ;
    angus2 = n%2==1 ? angus+slotAngle/2:angus; 
    
    rotate([0,0,-angus2+slotAngle/4 ])
    rotate([0,0,-slotAngle/4 ])
    {
  r1 = arrowRadius-pinRadius/3;
  r2 = arrowRadius+pinRadius/3;
  r3 =arrowRadius;
  
  linear_extrude(height=1)
  circleSeg(r1,r2,-slotAngle/2+headArc);
  

  //Arrow Head
    i=-slotAngle/2;
   point1 = [(r3+pinRadius)*sin(i+headArc),(r3+pinRadius)*cos(i+headArc)];
   point2 = [(r3-pinRadius)*sin(i+headArc),(r3-pinRadius)*cos(i+headArc)];
   point3 = [r3*sin(i),r3*cos(i)];

  points = [ point1,  point2, point3];
  linear_extrude(height=1)
 polygon(points);
 }
}

module output(turning){
    
    color([0,0.5,0],1)
    
    render(convexity=5)
    difference(){
        cylinder(h=1,r=outputDiscRadius,$fn=outfn);
        translate([0,0,-1])
        scale([1,1,3])
        slots(n);

        if(showOutputHoles){
                    for(i=[1:1:n]){
            S1=[a,r];
                        rotate([0,0,slotAngle*i])
            translate(S1)
          cylinder(h=1,pinRadius);
                    }
        }
    
    };
    
    if(volume){
      translate([0,0,1])
      color([0.5,1.0,0.5],0.5)
     cylinder(h=1,r=outputDiscRadius,$fn=outfn);
    }
    

    translate([0,0,2])
    color([0.5,1,0.5],1)
    cylinder(h=10,r=pinRadius,$fn=outfn);

    color("yellow")
    if(turning && arrows){
    translate([0,0,10])
    rotate([180,0,0])
           linear_extrude(height=1)
        if(arrows){
            arrow_quad();
            rotate([0,0,180])
            arrow_quad();
        }
        
        translate([0,0,-0.5])
        outputArrow(turning);
        
    }
}

module support(){
    
    S0=[0,0];
    S1=[r,a];
    S2=[r*3,a*3];
    S3=[r+a*2.5,a-r*2.5];
    
        color("blue",opacity)
        translate(S1)
        translate([0,0,-2-gap])
        cylinder(h=1, r=pinRadius*2, $fn=60);

            color([0.5,0.5,1],opacity)
    translate([0,0,-2-gap+0.25])
    hull(){
        translate(S1)
        cylinder(h=1/2, r=pinRadius, $fn=60);
        
        //translate([outputDiscRadius,outputDiscRadius,0])
        translate(S2)
        cylinder(h=1/2, r=pinRadius, $fn=60);
    }
    
    color([0.5,0.5,1],opacity)
    translate([0,0,-2-gap+0.25])
    hull(){
        translate(S1)
        cylinder(h=1/2, r=pinRadius, $fn=60);
        
        translate(S3)
        cylinder(h=1/2, r=pinRadius, $fn=60);
    }

    color([0.5,0.5,1],opacity)
    translate([0,0,-2-gap+0.25])
    if(n>3)hull(){
        translate(S0)
        cylinder(h=1/2, r=pinRadius, $fn=60);
        
        translate(S1)
        cylinder(h=1/2, r=pinRadius, $fn=60);
    }
    if(n>3){
    translate([0,0,-3])
    translate(S0)
    cylinder(h=8,r=pinRadius/2);
    }
    

    translate([0,0,-3])
    translate(S2)
    cylinder(h=8,r=pinRadius/2);
    

    translate([0,0,-3])
    translate(S3)
    cylinder(h=8,r=pinRadius/2);
    if(showUglySupport){
        translate([-r,-r*2,+5])
        cube([35,35,2]);
    }

    translate([0,0,+3])
    hull(){
        translate(S0)
        cylinder(h=1,r=pinRadius*2);
        translate(S2)
        cylinder(h=1,r=pinRadius*2);
        translate(S3)
        cylinder(h=1,r=pinRadius*2);        
    }
}

a=l2;
function pinAngle(ang)= let(point = [
    r + cos(ang)*r,
    a + sin(ang)*r] ) atan2(point.y, point.x);

pinAngle = pinAngle(ang);

turning = ang<180 ? true : ang >270+(90-slotAngle) ? true : false; 
outputAngle = turning ? pinAngle : 90;

if(volume){
    if(showInput){
        input();
    }
    if(showOutput){
        rotate([0,0,outputAngle])
        output(turning);
    }
    if(showSupport){
        support();
    }
}else{
   if(showInput){
        projection()
        input();
    }
    projection(){
        if(showOutput){
            output();
        }
    }
}

build.py[edit]

#!/usr/bin/env python3
import subprocess
import sys
import os

minSlots = 3
maxSlots = 9

#minSlots = 3
#maxSlots = 3
os.system("rm *.svg")
os.system("rm *.gif")
os.system("rm *.png")

#top view
for n in range(minSlots,maxSlots + 1,1):
    a = ""
    a = a + "'" + os.getcwd() +"/"+ "mechanism.scad" + "'" + " "
    a = a + "-o "+ "'" + os.getcwd()+"/Internal Geneva Wheel top view "+str(n)+".svg"+ "'" + " "
    a = a + "-D" + "n=" +str(n) + " "
    a = a + "-D" + "volume=false" + " "
    a = a + "-D" + "arrows=false" + " "
    a = a + "-D" + "showInput=false" + " "
    os.system("openscad " + a) 
    os.system("sleep 1") 
#exit();

for n in range(minSlots,maxSlots + 1,1):
    a = ""
    a = a + "'" + os.getcwd() +"/"+ "mechanism.scad" + "'" + " "
    a = a + "-o "+ "'" + os.getcwd()+"/"+"a"+".png"+ "'" + " "
    a = a + "--animate "+ "36" + " "
    a = a + "-D" + "n=" +str(n) + " "
    a = a + "--imgsize=1024,1024 "
    a = a + "--camera="
    a = a + "0.00,0.0,-0.0,"    #translation
    a = a + "180.00,0.00,0.00," #rotation #[ 180.00, 0.00, 0.00 ]
    a = a + "140" + " "         #distance
    a = a + "--projection o" 
    #a = a + "--viewall"
    print(a)
    
    os.system("openscad " + a) 
    os.system("sleep 1") 
    
    #os.system("convert -brightness-contrast 10x5 a*.png z.png")
    #os.system("./toGIFs.sh") 
    
    os.system("convert -brightness-contrast 10x5 -delay 10 -loop 0 *.png"+" "+"'" + "Internal Geneva Wheel top view "+str(n)+".gif"+"'") 
    os.system("sleep 1") 
        
    os.system("rm *.png")
    os.system("sleep 5") 

#exit();
 
#side view
for n in range(minSlots,maxSlots + 1,1):
    a = ""
    a = a + "'" + os.getcwd() +"/"+ "mechanism.scad" + "'" + " "
    a = a + "-o "+ "'" + os.getcwd()+"/"+"z"+".png"+ "'" + " "
    a = a + "--animate "+ "36" + " "
    a = a + "-D" + "n=" +str(n) + " "
    a = a + "--imgsize=1024,1024 "
    a = a + "--camera=0.02,0.28,-0.11,218.10,0.00,11.180,140" + " "
    #  [ 2.02, 0.28, -0.11 ] #translation
    #[ 218.10, 0.00, 11.70 ] #rotation
    #8   2.67                #distance
    #a = a + "--viewall"
    print(a)
    
    os.system("openscad " + a) 
    os.system("sleep 1") 
    
    #os.system("./toGIFs.sh") 
    os.system("convert -delay 10 -loop 0 *.png"+" "+"'" + "Internal Geneva Wheel "+str(n)+".gif"+"'" ) 
    os.system("sleep 1") 
    
    os.system("rm *.png")
    os.system("sleep 5") 


Categories[edit]

Category:Interior Geneva drive]] Category:Created with OpenSCAD]]