Author Topic: a simple clip  (Read 167 times)

raymw

  • Newbie
  • *
  • Posts: 28
    • View Profile
a simple clip
« on: 2020-08-29, 00:23:47 »
You can buy similar items for pennies, but if the shops are shut...

Having got a bit fed up with cutting/replacing cable ties, i thought of an alternative, similar to items I'd seen in garden centres for clipping plants to supports. As I have a 3d printer with nothing to do, i used AngelCad to make a similar clip, and thought that I could print it at different sizes, for holding different things, and if I used Pet-G filament, it would withstand the greenhouse temperatures, and unlike PLA, would be unlikely to bio-degrade.
So, here's some script with comments -

Code: [Select]
// AngelCAD code.

// Based on AngelCAD sample: screw_threads.as
// demonstrate use of rotate_extrude with non-zero pitch to create screw threads.

double wirediam = 3;
double gripdiam = 8; // inside diameter of coil.


//**************************
double ol = wirediam/10 ; // overlap
double gripr = (gripdiam +wirediam)/2;
double wirer = wirediam/2;
double len = gripr + wirer;

solid@ end()   // straight end with knob
{
  // generate ends
  solid@ end = cylinder (len,wirer/0.99);  // fudged the diameter of end
  solid@ ball= sphere(wirediam/1.2);
  return end+translate(0,0,len)*ball;
}

solid@ coil()
{
   // comments from screw_threads.as example
   // create a polygon from the points,
   // and position the resulting profile on the positive x-axis
   // shape2d@ poly = translate(gripr,0)*rotate_z(deg:-90)*circle(wirer);
 
   shape2d@ poly = translate(gripr,0)*circle(wirer);

   // perform 1 full rotations, with s small pitch to offset the threads
return rotate_extrude(poly,deg:360*1,pitch:wirediam*1.1);  //single turn coil
}

shape@ all() // put the ends onto the coil
{
  solid@ end1= translate(gripr,0,ol)*rotate_y(180)*end();
  solid@ end2= translate(gripr,wirediam*1.1,-ol)*end();
return end1 + end2  + coil();
}

void main()
{
   shape@ obj = all();
   obj.write_xcsg(GetInputFullPath(),secant_tolerance:0.01);
}

I ran into a problem, because the ends of the coil are not cut on the x/y plane, which presents an angle to the two end pieces. I added an overlap to remove the gap, but found that It would not complete for wire diameters over 2.0, or so. I fudged it again, by making the end pieces slightly larger. This works, but it is not particularly elegant. It would be better to generate  a path from end to end, and extrude along that. However, these loops are now holding up my tomato plants, and smaller ones will be used as cable clips on the printer as originally intended. They print OK, lying flat, with a few supports.

edit to add a couple of quick pics
« Last Edit: 2020-08-29, 21:52:48 by raymw »

Carsten Arnholm

  • Administrator
  • Newbie
  • *****
  • Posts: 45
    • View Profile
Re: a simple clip
« Reply #1 on: 2020-08-29, 09:16:53 »
I ran into a problem, because the ends of the coil are not cut on the x/y plane, which presents an angle to the two end pieces. I added an overlap to remove the gap, but found that It would not complete for wire diameters over 2.0, or so. I fudged it again, by making the end pieces slightly larger. This works, but it is not particularly elegant. It would be better to generate  a path from end to end, and extrude along that. However, these loops are now holding up my tomato plants, and smaller ones will be used as cable clips on the printer as originally intended. They print OK, lying flat, with a few supports.

Nice work! The problem you describe is a classic one. In AngelCAD (and also OpenSCAD), the solid geometry is represented as a surface mesh, i.e. the surface of the solid is described by flat polygons, usually of the simplest variant; triangles.

You can not perfectly describe the surface of a coil like that using a triangle surface mesh, it is just an approximation. Likewise, you cannot perfectly describe the surface mesh of a straight cylinder using a triangle surface mesh, it is another approximation. When you try to union the two at the coil/cylinder ends you typically run into a problem: the two approximations are not the same and therefore the mating of the two can often fail, and you have to make tweaks like you did to make it work.

Having realised this, the solution is often to try a different approach where the problem of incompatible cylindrical end approximations are avoided. One way is to sweep the whole shape in a single operation:

Code: [Select]
// AngelCAD code.

shape@ main_shape()
{
   double wirediam = 3.0;
   double gripdiam = 8.0;
   return coil(wirediam,gripdiam);
}

solid@ coil(double wirediam, double gripdiam)
{
   // NOTE: This code has some kind of bug in creating 3d spline that
   // makes the coil radius twice what it should be
   // I have therefore made some tweaks to adjust for that.
   // The bug should be investigated...
   
   
   // create the profile to be swept
   double radius    = (gripdiam +wirediam)/4.0;
   shape2d@ profile = translate(radius,0)*circle(wirediam/2);
   
   double len   = 2*radius + wirediam/2;
   double pitch = wirediam*1.1;
   pos3d start(radius,0,-len);
   pos3d end(radius,pitch,len);
   
   // create the 2 first spline points
   array<pos3d@> points = { start, (start+pos3d(radius,0,-len/2))*0.5 };

   // create points around the coil
   for(double angle=0.0; angle<=2*PI; angle+=PI/9.) {
      double x = radius*cos(angle);
      double y = pitch*angle/(2*PI);
      double z = radius*sin(angle);
      points.push_back( pos3d(x,y,z) );
   }
   
   // create the 2 last spline points
   pos3d@ p = points[points.size()-1];
   points.push_back((p+end)*0.5);
   points.push_back(end);

   // create the spline
   spline_path@ path = spline_path(points,vec3d(0,1,0));
   solid@ ball= sphere(wirediam/1.2);
   
   // create the coild and add the balls
   return sweep(profile,path) + translate(start.x()*2,start.y(),start.z())*ball
                              + translate(end.x()*2,end.y(),end.z())*ball;
}


void main()
{
   shape@ obj = main_shape();
   obj.write_xcsg(GetInputFullPath(),secant_tolerance:0.01);
}

Here, we create a 3-dimensional spline curve that describes the central line through your coil, including the semi-straight ends. Then we use AngelCADs sweep function to sweep the circle along that spline path. This means we do not have to add the cylindrical ends, and therefore we do not have any problems with incompatible surface mesh approximations.




raymw

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: a simple clip
« Reply #2 on: 2020-08-29, 12:42:34 »
Thanks. I'll use that for the next batch I print. I can't see the difference in sizes in my original version, but can see the angle in the join. Not sure if the slicer picks out the change in diameter between end and coil, or if it does if the extruder can.