I've been recently printing using pet-g. I find it has good mechanical properties for what I want, or at least better than abs or pla. It can be ground, filed and machined, without too many problems. I was thinking of using it for jigs and fixtures, clamps, etc, and was wondering about trying some rule of thumb tests. I designed a T nut, with a 12mm thread. Knowing that holes came out undersize, I changed the od to 12.2, it printed, but still a bit tight on the 12mm stud, so I ran a tap down through. I think the fit could be improved by using a 12mm od thread, as it should be, but I found it would not accept exactly 12mm. I based the code on Carsten's example. Here's my code. the '//this line' comment, was left from when I was originally going to tap a plain hole, but if it is removed, or changed to the root diameter, the code fails. I think, because of the countersinks interacting with the thread ends, it causes confusion in the rendering, changing the secant_tolerance dramatically effects the result.
// AngelCAD code.
double to_rad(double deg) { return PI*deg/180.0; } // from degrees to radians
shape2d@ ISO_thread(double Dmaj, double pitch)
{
double P = pitch;
// basic thread profile https://en.wikipedia.org/wiki/ISO_metric_screw_thread
double H = P*cos(to_rad(30));
double delta = 0.01*P;
// establish coordinates in profile
double x1 = delta;;
double x2 = P/8;
double x3 = P/2 - P/16;
double x4 = P/2 + P/16;
double x5 = P - P/8;
double x6 = P - delta;
double y1 = 0;
double y2 = H/4 - P/16;
double y3 = H/4;
double y4 = H - H/8;
// build the thread profile, points CCW
pos2d@[] points = { pos2d(x1,y1), // p0
pos2d(x6,y1), // p1
pos2d(x6,y2), // p2
pos2d(x5,y3), // p3
pos2d(x4,y4), // p4
pos2d(x3,y4), // p5
pos2d(x2,y3), // p6
pos2d(x1,y2) // p7
};
shape2d@ profile = polygon(points);
// put the profile in place, ready for rotation around Y
@profile = translate(0.5*Dmaj-H+H/8,P/2)*rotate_z(deg:-90)*profile;
return profile;
}
solid@ ISO_screw(double Dmaj, double pitch)
{
// EXPERIMENTAL: non-zero pitch and multiple revolutions
// rotate profile around Y, 13 revolutions, then make it upright
double revs = 15;
shape2d@ thread_profile = ISO_thread(Dmaj:Dmaj,pitch:pitch);
solid@ threads = translate(0,0,pitch*revs)*rotate_x(deg:90)*rotate_extrude(thread_profile,deg:360*revs,pitch:-pitch);
//make a cylinder inside the threads, then cut the ends by intersecting with a large diameter cylinder
double H = pitch*cos(to_rad(30));
double Dmin = Dmaj + 2*(H/8 - H + 0.8*H/4);
double Rmin = 0.5*Dmin;
solid@ rod = cylinder(r:Rmin,h:pitch*revs);
solid@ screw = intersection3d(union3d(rod,threads),translate(0,0,0.5*pitch)*cylinder(h:pitch*revs*0.9,r:100));
solid@ cutter = cone(h:pitch*revs*1.3,r1:Dmaj*1.35,r2:1);
return translate(0,0,-5)*intersection3d(screw,cutter);
}
shape@ main_shape()
{
// t nut with 10mm hole
solid@ mynut = cuboid(28,22,8);
@mynut = mynut + translate (0,4,0)*cuboid(28,14,15);
// hole
@mynut= mynut -translate(14,11,0)* cylinder(50,4); //this line
solid@ bolt = ISO_screw(12.05,1.75) ;
// add countersinks
solid@ cs = translate(14,11,4)*cone (17.3,0,10);
solid@ uc = translate(14,11,-6.3)*cone(17.3,10,0);
return mynut- translate( 14,11,0)* bolt -cs - uc;
}
void main()
{
shape@ obj = main_shape();
obj.write_xcsg(GetInputFullPath(),secant_tolerance:0.05);
}