3D part design with OpenSCAD#144: Improving the Protractor tool that I started to make in post # 50.

3D part design with OpenSCAD#144: Improving the Protractor tool that I started to make in post # 50.

After my last post I needed a way to find an angle after scaling a part using the scale function of linear_extrude. I went to use the protractor from post #50 and it was unfinished and pretty hard to use so I decided to make some improvements. Of course the built in angle finder in OpenSCAD works just fine but it's fun for me to try things like this and the more I experiment the more I learn and come up with ideas for other projects. Once again there is some work to do but I have added a trig triangle calculator and will be adding a lot more functionality as I get time and figure out how I want it to work.

I used linear_extrude scale to angle the sides of the pan but I was having a difficult time figuring out the exact angle I needed to use to adjust the ridges automatically so I made a calculator that will calculate the angle automatically for me.

First I saved just the ring of the pan to an stl file:

Then I imported it into my calculator:

Now I can adjust the settings until they line up and this will give me the right angle I need.

Here is the code for the calculator:

//

/*[Extrude Scale Angle Calculator]*/
Diameter=254;//[50:.01:400]
Scale=1;//[-1.00:.001:10.00]
Height=10;//[1.00:.001:100.00]
Shape=100;//[3:1:100]

linear_extrude(Height,scale=Scale)
circle(Diameter/2,$fn=Shape);

/*[Hidden]*/
$fa=$preview? 2:1;;
$fs=$preview?.5:.1;;

Radius=Diameter/2;
Opposite=Radius*Scale-Radius;
Adjacent=Height;
Hypotenuse=sqrt(Opposite^2+Adjacent^2);
Angle_h=((Opposite*Adjacent)/Hypotenuse);
Angle_a=asin(Opposite/Hypotenuse);
Angle_b=asin(Adjacent/Hypotenuse);

echo(Hypotenuse=(Hypotenuse));
echo(Angle_a=(Angle_a));
echo(Angle_b=(Angle_b));
echo(Angle_h=(Angle_h));
echo(Opposite=(Opposite));
echo(Adjacent=(Adjacent));
echo(Scale);
#import("/home/none4/Desktop/gold pan.stl");

Just delete the path in that last import line and insert your own to try it out.

Once I knew I need an angle of 64.712 I imported the pan into my protractor code to test it to see how accurate it is:

I set the stl import to be transparent using # so it would be easy to see where the edge of the object was.

It looks like the protractor and the trig calculator are spot on with what my extrude scale calculator was calculating.

Here is the updated protractor code:


//

/*[STL Import]*/
Show_STL=false;
Path_to_STL_file="File.stl";
Move_STL_X=0;//[-400:.01:400]
Move_STL_Y=0;//[-400:.01:400]
Move_STL_Z=0;//[-400:.01:400]
Rotate_STL_X=0;//[-400:.01:400]
Rotate_STL_Y=0;//[-400:.01:400]
Rotate_STL_Z=0;//[-400:.01:400]

/*[Protractor]*/
Show_Protractor=true;
Protractor_diameter=400;//[.1:.1:1000]
Rotate_angle=0;// [-360.00:.01:360.00]

/*[Trig Triangle]*/
//Adjacent=Protractor_diameter//
Show_Trig_Triangle=true;
Opposite=200;//[0:.01:1000]

/*[Ruler]*/
Show_ruler=true;
Scale=25.4;//[0:.01:60]

/*[Angle Text]*/
text1=str(Rotate_angle);
length1=len(text1);
text10=str(Rotate_angle+(-180));
length10=len(text10);

/*[Side Text]*/
Show_side_text=true;

/*[Formulas]*/
Pd=Protractor_diameter/2;
Radius = Protractor_diameter/2;
Area = PI*(Radius^2);
Degrees = Rotate_angle;
Arc_length = Degrees*(PI/180)*Radius;
Arc = str(Arc_length);
T_Opposite=Opposite;
T_Adjacent=Pd;
Hypotenuse=sqrt(Opposite^2+Pd^2);
Angle_h=((Opposite*Pd)/Hypotenuse);
Angle_a=asin(Opposite/Hypotenuse);
Angle_b=asin(Pd/Hypotenuse);
Sine=(Opposite/Hypotenuse);
Cosine=(Pd/Hypotenuse);
Tangient=(Opposite/Pd);

/*[Trig Text]*/
text2=str(Angle_b);
length2=len(text2);
text3=str(Angle_a);
length3=len(text3);
text4=str(Opposite);
length4=len(text4);
text5=str(Pd);
length5=len(text5);
text6=str(Sine);
length6=len(text6);
text7=str(Cosine);
length7=len(text7);
text8=str(Tangient);
length8=len(text8);
text9=str(Hypotenuse);
length9=len(text9);

/*[Ruler text]*/
text11=str(-Pd);
length11=len(text10);
text12=str(Pd*2);
length12=len(text10);

/*[Hidden]*/
$fa=$preview? 2:1;;
$fs=$preview?.5:.1;;

module Protractor(){
 if(Show_Protractor){
//Line
   rotate([0,Rotate_angle,0])
   rotate([90,0,0])
   translate([0,-Pd-64,0])
   color("yellow",.5)
   cube([2,Pd*2+130,12]);
//Inner circle 
   rotate([0,Rotate_angle,0])
   rotate([90,0,0])
   color("royalblue",.5)
   linear_extrude(10)
   circle(Pd,$fn=200);
//Grey ring  
   rotate([0,Rotate_angle,0])
   rotate([90,0,0])
   color("dimgrey")
   linear_extrude(8)
   circle(Pd+60,$fn=200);
//external ring  
   rotate([0,Rotate_angle,0])
   rotate([90,0,0])
   color("royalblue")
   linear_extrude(6)
   circle(Pd+100,$fn=200);
}}

module Trig_triangle(){
 rotate([90,0,180])
 translate([-Pd,0,-16])
 resize([T_Adjacent,T_Opposite,24])
 linear_extrude(16)
 polygon(points=[[0,0],[10,0],[0,10],[0,0],[80,0],[0,80]],
 paths=[[0,0,0],[3,4,5]],convexity=10);
}

module ruler(){
   rotate([0,-90,0])
   rotate([90,0,0])
   translate([-12.7,-Pd,-12.7])
   color("yellow",.6)
   cube([12.7,Pd*2,25.4]);
  for(i=[0:Scale:Pd])
   translate([i,0,0])
   rotate([90,0,90])
   color("red",.5)
   translate([0,-6.35,0])
   cube([26,13,.1],center=true);
  for(j=[0:-Scale:-Pd])
   translate([j,0,0])
   rotate([90,0,90])
   color("red")
   translate([0,-6.35,0])
   cube([26,13,.1],center=true); 
}

module ruler_text(){
 translate([Pd,-12.7,-12.7])
  rotate([90,0,0])
  color("red")
  linear_extrude(1)
    text(str(text5),size=5,font ="", 
    halign="center", valign="center",spacing =1,
    direction="ltr",$fn=100);
 translate([-Pd,-12.7,-12.7])
  rotate([90,0,0])
  color("red")
  linear_extrude(1)
    text(str(text11),size=5,font ="", 
    halign="center", valign="center",spacing =1,
    direction="ltr",$fn=100);
  translate([0,-12.7,-12.7])
  rotate([90,0,0])
  color("red")
  linear_extrude(1)
    text(str(text12),size=5,font ="", 
    halign="center", valign="center",spacing =1,
    direction="ltr",$fn=100);
}
    
module Protractor_text(){
//Upper angle text
 rotate([0,Rotate_angle,0])
 translate([0,12,Pd+68])
 rotate([90,0,0])
 linear_extrude(24)
 text(str(text1),size=20,font ="", 
 halign="center", valign="bottom",spacing =1,
 direction="ltr",$fn=100);
//Lower angle text 
 rotate([0,Rotate_angle,0])
 translate([0,12,-Pd-88])
 rotate([90,0,0])
 linear_extrude(24)
 text(str(text10),size=20,font ="", 
 halign="center", valign="bottom",spacing =1,
 direction="ltr",$fn=100);
}

module Trig_triangle_text(){
//(Angle_b)//
  translate([8,-12,-6])
  rotate([90,0,0])
  linear_extrude(2)
    text(str(text2),size=4,font ="", 
    halign="left", valign="bottom",spacing =1,
    direction="ltr",$fn=100);
//(Angle_a)//    
  translate([Pd+3,-10,Opposite-12])
  rotate([90,0,0])
    linear_extrude(2)
    text(str(text3),size=4,font ="", 
    halign="left", valign="bottom",spacing =1,
    direction="ltr",$fn=100);   
//(Opposite side length)//    
  translate([Pd-9,-12,Opposite/2])
  rotate([90,90,0])
  linear_extrude(2)
    text(str(text4),size=4,font ="", 
    halign="center", valign="bottom",spacing =1,
    direction="ltr",$fn=100); 
//(Adjacent side Length)//  
  translate([Pd/2,-12,5])
  rotate([90,0,0])
  linear_extrude(2)
    text(str(text5),size=4,font ="", 
    halign="center", valign="center",spacing =1,
    direction="ltr",$fn=100);
//(Hypotenuse Length)//  
  translate([Pd/2,-12,Opposite/2])
  rotate(a=[90,-Angle_a,0])
  linear_extrude(2)
    text(str(text9),size=4,font ="", 
    halign="center", valign="top",spacing =1,
    direction="ltr",$fn=100); 
}

module Side_text(){
//(Sine)//
 translate([65,-12,-46])
 rotate([90,0,0])
 linear_extrude(2)
 text(str(text6),size=10,font ="", 
    halign="left", valign="bottom",spacing =1,
    direction="ltr",$fn=100); 
 translate([10,-12,-47])
 rotate([90,0,0])
 linear_extrude(2)    
 text("(Sin)",size=10,font ="", 
    halign="left", valign="bottom",spacing =1,
    direction="ltr",$fn=100); 
//(Cosine)//
 translate([65,-12,-64])
 rotate([90,0,0])
 linear_extrude(2)
 text(str(text7),size=10,font ="", 
    halign="left", valign="bottom",spacing =1,
    direction="ltr",$fn=100); 
 translate([10,-12,-66])
 rotate([90,0,0])
 linear_extrude(2)    
 text("(Cos)",size=10,font ="", 
    halign="left", valign="bottom",spacing =1,
    direction="ltr",$fn=100);     
//(Tangient)//
 translate([65,-12,-84])
 rotate([90,0,0])
 linear_extrude(2)
 text(str(text8),size=10,font ="", 
    halign="left", valign="bottom",spacing =1,
    direction="ltr",$fn=100); 
 translate([10,-12,-86])
 rotate([90,0,0])
 linear_extrude(2)    
 text("(Tan)",size=10,font ="", 
    halign="left", valign="bottom",spacing =1,
    direction="ltr",$fn=100);      
    
}

module STL_import(){
import(Path_to_STL_file,center=true);
}

if(Show_Trig_Triangle){
difference(){
translate([0,4,0])
color("skyblue",.4)
Trig_triangle();
Protractor();
}
color("red")
Trig_triangle_text();
}
    
if(Show_Protractor){
render()
Protractor();
color("yellow")
Protractor_text();
mirror([0,1,0])
Protractor();
}

if(Show_STL){
translate([Move_STL_X,Move_STL_Y,Move_STL_Z])
rotate([Rotate_STL_X,Rotate_STL_Y,Rotate_STL_Z])
color("red",.5)
STL_import();
}

if(Show_side_text){
color("yellow")
Side_text();
}

if(Show_ruler){
ruler();
ruler_text();
}

Now it will be easy to add some text that shows more calculations.

I'm sure I probably missed something or made some errors I didn't catch because I always seem to find mistakes a day or two later so I will be updating this post as I find them.