Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - raymw

Pages: [1] 2 3
1
exactly as posted (without the fillet operational) it takes 1 minute and 27 seconds in openscad on my machine, and in angelcad, it produces a couple of lines -  UNEXPECTED face loop with size != 1.
UNEXPECTED face loop with size != 1. (and other messages as well), and a broken model. This is what I was getting at, what runs in openscad slowly, may not run at all in angelcad. I initially ran it in angelcad, with the fillet, since that took far to long in openscad. It did not run properly in angel cad, so I commented out the fillet code, and it still did not run in angel cad. I've just run this commented code, exactly as shown in the forum, and on my pc it takes 1 minute and 27 seconds in openscad. Your machine must be a bit faster, but it still does not run in Angel cad. It would be nice to know what causes the unexpected face loop, but I eventually got a result in openscad that was good enough. 

2
The threading stuff is in  NopSCADlib and comes from https://github.com/nophead/NopSCADlib as you said.
The fillet was found on https://www.thingiverse.com/thing:2461392  there is a slight error in the code, I corrected it and reported it to the author, not sure if he fixed it, (I've attached that file*, but you can comment that out in my example). The problem is, that If I can't get things to work, then I try another way, and tend to forget the details of the original problem, which is probably not much help to you.

* for some reason, it couldn't get the path to the zip file for the attachment, so it's all below

Code: [Select]



/*
Created by Kevin Gravier
https://www.thingiverse.com/mrkmg/about

My take on a top and bottom fillet for a 3d shape.

Available Modules:

topBottomFillet(b, t, r, s, e)
b = z of bottom of 3d object
t = z of top of 3d object
r = radius of fillet
s = steps of filler (smaller is smoother)
e = enabled (pass e = 0 to disable fillet for faster preview)

topFillet(t, r, s, e)
t = z of top of 3d object
r = radius of fillet
s = steps of filler (smaller is smoother)
e = enabled (pass e = 0 to disable fillet for faster preview)

bottomFillet(b, r, s, e)
b = z of bottom of 3d object
r = radius of fillet
s = steps of filler (smaller is smoother)
e = enabled (pass e = 0 to disable fillet for faster preview)

*/

enable = 1;
/*
// Example, hard edges
translate([0, 20, 0])
topBottomFillet(b = 0, t = 10, r = 2, s = 20, e = enable)
linear_extrude(10, scale = 1.2)
difference() {
    union() {
        square([10, 10], true);
        translate([-15, 0]) circle(15);
    }
    translate([-15, 0]) circle(8);
    translate([-15, 0]) square([13, 13], center = true);
}

// Example, soft edges
use <fillets2d.scad>;
translate([0, -20, 0])
topBottomFillet(b = 0, t = 10, r = 1, s = 10, e = enable)
linear_extrude(10)
rounding2d(1)
fillet2d(1)
difference() {
    union() {
        square([10, 10], true);
        translate([-15, 0]) circle(15);
    }
    translate([-15, 0]) circle(8);
    translate([-15, 0]) square([13, 13], center = true);
}


// Example, text
translate([-60, 40])
rotate([0, 0, -90])
topBottomFillet(b = 0, t = 3, r = .5, s = 5, e = enable)
linear_extrude(3)
text("Fillets!", size = 20);

*/
// Library

function filletDepth(r, d, i) = r * cos(asin(d * i / r));

module topBottomFillet(b = 0, t = 2, r = 1, s = 4, e = 1) {
    if (e == 1) {       
        topFilletPeice(t = t, r = r, s = s) children(0);
        bottomFilletPeice(b = b, r = r, s = s) children(0);
       
        render()
        difference() {
            children(0);
           
            translate([0, 0, t - r])
            linear_extrude(r + 1)
            offset(delta = 1e5)
            projection()
            children(0);
           
            translate([0, 0, b - 1])
            linear_extrude(r + 1)
            offset(delta = 1e5)
            projection()
            children(0);
           
        }
    }
    if (e == 0) children(0);
}

module topFillet(t = 2, r = 1, s = 4, e = 1) {
    if (e == 1) {
        topFilletPeice(t = t, r = r, s = s) children(0);
       
        render()
        difference() {
            children(0);
            translate([0, 0, t-r])
            linear_extrude(r + 1)
            offset(delta = 1e5)
            projection()
            children(0);
        }
    }
    if (e == 0) children(0);
}

module bottomFillet(b = 0, r = 1, s = 4, e = 1) {
    if (e == 1) {
        bottomFilletPeice(b = b, r = r, s = s) children(0);
       
        render()
        difference() {
            children(0);
            translate([0, 0, b -  1])
            linear_extrude(r + 1)
            offset(delta = 1e5)
            projection()
            children(0);
        }
    }
    if (e == 0) children(0);
}

module topFilletPeice(t = 2, r = 1, s = 4) {
    d = r/s;
       
    for (i = [0:s]) {
        x = filletDepth(r, d, i);
        z = d * (s - i + 1);                 
        translate([0, 0, t - z])
        linear_extrude(d)
        offset(delta = -r + x)
        projection(true)
        translate([0, 0, -t + z])
        children(0);
    }
}

module bottomFilletPeice(b = 0, r =1, s = 4) {
    d = r/s;
       
    for (i = [0:s]) {
        x = filletDepth(r, d, i);
        z = d * (s - i);
        translate([0, 0, b + z])
        linear_extrude(d)
        offset(delta = -r + x)
        projection(true)
        translate([0, 0, b - z])
        children(0);
    }
}

3
This is not what i wanted to show, since it does not work in angel cad, but does very slowly in openscad, but I had to comment out the fillet, I gave up waiting. There are a number of near misses with curves. If you've not got nophead'  library, then even if you comment out the 'male_metric_thread' line, it still won't work in angelcad, but it did more or less yesterday, iirc, because I experimented with the secant_tolerance values, smoothing out the curves.

Code: [Select]
//twist nut 8mm blank
include<NopSCADlib/utils/thread.scad>
include<rw/fillets3d.scad>

//module male_metric_thread(d, pitch, length, center = true, top = -1, bot = -1, solid = true, colour = undef) { //! Create male thread with metric profile example for variable names


//bottomFillet(b=0,r=1.5,s=8,e=enable)
translate([0,0,10])
difference(){
    union(){
      translate ([0,0, 5])  sphere( 12);
  scale([1.5,1,1])translate ([0,0,-5])  rotate ([90,0,0]) cylinder(h=3,d=15,center=true);
  cylinder (h=20,d=16,center=true);
  //  translate([0,0,10])cylinder (h=3,d=13);
    }
male_metric_thread(8,1.25,21);
 translate([0,0,-2])rotate([0,6,0])cylinder (h=21,d=8.2,center=true);   
   
  translate([0,0,-60])  cube([100,100,100],true); //chop off bottom
   
   
}


$fn=80;
//topBottomFillet(b = 0, t = 10, r = 1, s = 10, e = enable)

4
This runs considerably faster than rendering within openscad, seconds instead of many minutes in the few tests I've done. Would it be possible to parse the openscad script, and extract the $fn=80; (or similar values) and prefill the 'args' with a suitable value for secant_tolerance?

6
General Discussion / Re: Threads - ISO
« on: 2020-09-13, 14:15:35 »
Hi Carsten,
The line in my code ' @mynut= mynut -translate(14,11,0)* cylinder(50,4); //this line'
is from before I used your threading code, I was simply 'drilling' a plain hole, and tapping it when printed. I was thinking it should not be required, as I thought your code removed the core of the thread, but if that line is altered too much, or removed, then the script does not work, It also fails if the depth of countersink (the h values in the cones) is altered or the secant_tolerance value. It becomes a bit of a juggling act. It just happened that my original 12.2 od was OK, but 12.0 od  is not.

So, if you change the value for the diameter of the cylinder in ' //this line' e.g. to 5.35,  (10.7mm being  the tapping drill size for 12mm bolt), it looks OK, change to 5.355 it throws an exception, and I get other errors by altering that value. Comment out that line, then  sometimes it completes OK, sometimes a blank screen, sometimes an image with red. It seems to be almost random behavior.

This type of  problem seems to be getting quite common with what I am doing, and seem to be not too repeatable. If you do not get this happening then either, my installation is faulty, I have pc memory problems, or your version/setup is different than mine.

7
General Discussion / Threads - ISO
« on: 2020-09-12, 15:34:18 »
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.

Code: [Select]
// 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);
}

8
General Discussion / Re: console mesages
« on: 2020-09-09, 16:08:14 »
I've not heard of polyfix, but will try it. Anyway, I found the problem area, and resolved it, but not before I'd produced a print that fell apart when I lifted it from the print bed. (It looked OK in the slicer.)
Code: [Select]
// AngelCAD code.

// makes a spoked handwheel

double bore =8.2;// bore
double shaft=20;//shaft od
double shaftlen=40;//shaft length
double borelen=25;//bore length
double rimod=50;// rim od
double rimid=38;//rim id
double rimthick=8;// rim thickness
double spokes=5;//no of spokes
double fixloc=8;//fix location from boss end
double fixdiam=2;//fix diam
double grips=12;//number of grips
double round =3.5;// diameter of fillet


solid@ rim(double h,double d2,double d1, double rc)
{
// get tube
  solid@ arim= cylinder (h,d2/2) - cylinder(h,d1/2);
//fillet inside
 return arim;
}


solid@ aspoke(double t,double d, double n, double ch)
// get spoke
{
   double thick = (t-ch)*0.5; //spoke width
// make quarter spoke with rounded edge
// use offset, radius ch/2 of square for profile, then extrude
    solid@ spr= linear_extrude(offset2d(square(thick),r:ch/2),(d+(t))/2);
    solid@ spk = translate(0,-(thick/2),thick+ch/2)*rotate_y(90)*spr;
// rotate and add spokes
     array <solid@> total;
     for (int j=1;j<n+1;j++)
     {
        solid@ rotsp = rotate_z(j*360/n)* spk;
        total.push_back(rotsp);
     }
     return union3d(total);
}
 
 solid@ grip(double t,double d, double n)
// puts n balls on circle of diameter d. ball diameter is t
{
  array <solid@> balls;
 
 for (int j=1;j<=n;j++)
   {
    solid@ rotb = rotate_z(j*360/n)*translate(d/2,0,t/2)*sphere((t)*0.8/2);
    balls.push_back(rotb);
   }
   return union3d(balls);
}
 
  shape2d@ corner_poly(double filletdiam,double bigdiameter)
 {
 // generates polygon for rounding corners of tubes
     double  r= filletdiam/2;
     double br= bigdiameter/2;
     shape2d@  block = square(2*r);
     @block = block - translate(0,2*r)*circle(r);
     @block = block - translate(0,0)*circle(r);
     @block = block - translate(2*r,0)*circle(r);
     @block = block - translate(2*r,2*r)*circle(r);
     return translate(br,0)*translate(-r,-r)*block;
     return block;
 }
 
 
 solid@ round_over(double filletdiam, double circlediam)
 {// makes the profile to be subtracted from square ends
    shape2d@ poly = corner_poly(filletdiam,circlediam);
    solid@ curv = rotate_extrude(poly,360,0);
    @curv = rotate_x(90)*translate(0,filletdiam,0)*curv ;
    return translate(0,0,-filletdiam)*curv;
 }
 

 
 solid@ rwboss(double sl,double sd,double bl, double bo,double fixl, double fixd, double ch)
 // calc centre boss with fix hole
{
   solid@ shf=cylinder(sl,sd/2)-translate(0,0, sl-bl)*cylinder( bl, bo/2);
 //fixing  hole
    solid@ fix = rotate_y(90)*cylinder(sd*8,fixd/2);
    return shf  - translate(-sd*3,0,sl-fixl)*fix ;
 

   
shape@ main_shape()
{
  solid@ os=rim(rimthick,rimod,rimid, round);
  solid@ gripper =translate(0,0,0)*grip(rimthick,rimod,grips); 
  // fillet bottom of rim
  @os=os + gripper;
  @os = os - round_over(round,rimod);
  @os = os - round_over(round,rimid);
 
  //fillet top of rim
  @os = os - translate(0,0,rimthick)*round_over(round,rimod);;
  @os = os - translate(0,0,rimthick)*round_over(round,rimid);;
  @os=os + gripper;
// get shaft
   solid@ shft = rwboss(shaftlen,shaft, borelen,bore,fixloc,fixdiam,round);
   @shft= shft -round_over(round,shaft);
// bigger radius at shaft end   
   @shft = shft - translate(0,0,shaftlen)* round_over(round*2,shaft);
// get spokes
  solid@ spk = aspoke(rimthick,rimid,spokes,round);
 
 return os + spk + shft ;
 
}

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

The above code works. Previous version  problem was caused by the gripper balls diameter, and the order the handwheel was assembled. If the spheres were big, they did not merge properly with the rounded edge of the rim, and although everything looked fine in meshlab, and on the slicer, it looked good enough to print, but the object was not watertight. The spheres need to be less than the flat area of the rim to be certain it builds correctly, but in some situations they can be a bit larger. I'm pretty sure there are other combinations that fail, too.

9
General Discussion / Re: console mesages
« on: 2020-09-09, 00:34:16 »
I thought i had completed the handwheel project of mine. It produces an stl file that renders well in meshlab, but Cura, Slic3er and IceSlicer can not slice it properly- they each give different but wrong results. The saga continues..

10
General Discussion / Re: console mesages
« on: 2020-09-08, 20:55:18 »
I scrapped what i was doing, or at least the way i was trying to do it, and came up with this (part of a generic wheel creator I am thinking about). It produces rounded ends on tubes, and can be extended for straight slabs, too. The secret is in the polygon shape. The one shape allows inside and outside ends of a tube to be rounded. It seems quite robust, for once, for me. Instead of the polygon, then a square at 45deg, would chamfer the ends. Obvious limits in the relationship between the fillet diameter and inside diameter of the tube using this
Code: [Select]
/ AngelCAD code.

//
// rounds tube ends


double rimod=50;// rim od
double rimid=8;//rim id
double rimthick=48;// rim thickness
double round =10;// diameter of fillet

solid@ rim( double h, double od,double id)
 {
    return cylinder (h,od/2)-cylinder(h,id/2);
   
  }

 shape2d@ corner_poly(double filletdiam,double bigdiameter)
 {  // generates polygon for rounding corners
     double  r= filletdiam/2;
     double br= bigdiameter/2;
     shape2d@  block = square(2*r);
     @block = block - translate(0,2*r)*circle(r);
     @block = block - translate(0,0)*circle(r);
     @block = block - translate(2*r,0)*circle(r);
     @block = block - translate(2*r,2*r)*circle(r);
     return translate(br,0)*translate(-r,-r)*block;
     return block;
 }
 
 
 solid@ round_over(double filletdiam, double circlediam)
 {
    shape2d@ poly = corner_poly(filletdiam,circlediam);
    solid@ curv = rotate_extrude(poly,360,0);
    @curv = rotate_x(90)*translate(0,filletdiam,0)*curv ;
    return translate(0,0,-filletdiam)*curv;
 }
 
 
shape@ main_shape()
{
  solid@ os = rim(rimthick,rimod,rimid);
 @os = os - round_over(round,rimod); //bottom outside
 @os = os - translate(0,0,rimthick)*round_over(round,rimod); //top outside
 @os = os - round_over(round,rimid); //bottom inside
 @os = os - translate(0,0,rimthick)*round_over(round,rimid); //top inside
 return os;

}

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

11
General Discussion / console mesages
« on: 2020-09-08, 15:59:24 »
Hi,
Trying to tune up some code, making it more succint, to put in my library, and I find that it often does not complete execution. It seems often to struggle with tori. Below is the typical console message I get.
Code: [Select]
1796 > "C:\Program Files\AngelCAD\xcsg.exe" --csg --dxf --stl --svg --fullpath "C:\Users\Ray\Desktop\AngelCad\xcsg\handwheel2.xcsg"
xcsg processing: C:/Users/Ray/Desktop/AngelCad/xcsg/handwheel2.xcsg
processing solid: difference3d
...completed CSG tree: 21 boolean operations to process.
...starting boolean operations
...boolean progress: 9.5%
...boolean progress: 19%
...Info: rotate_extrude angle>=2*PI implies a torus
...boolean progress: 28.5%
...boolean progress: 38%
...boolean progress: 47.6%
...Info: rotate_extrude angle>=2*PI implies a torus
...boolean progress: 57.1%
...boolean progress: 66.6%
...Info: rotate_extrude angle>=2*PI implies a torus


playing with some values, or adjusting secant_tolerance may allow it to complete, but more often it stalls somewhere else. Is it possible to give more detail in the console messages, as to where in the script it may be failing? I comment out sections, etc., to try and find the error, but when perhaps I have a function that works most of the time, but sometimes when it is called, it stops, is it the function in error, or the calling that is the cause of failure? Alter the function, chances are it will not work where once it worked before.

edit, adjusted secant tolerance, and got this, as last two lines.
Code: [Select]
...Info: rotate_extrude angle>=2*PI implies a torus
xcsg finished with exception: (carve error): D:\cpde_dep\3rdparty\carve\lib\intersect_face_division.cpp:587  "implement me"

which most likely is a clue.

12
Thanks Carsten, I was neglecting the @mycub, and the error message I as getting, was not understanding what I was trying to do, but what it thought I was trying to do. So far, I've only played in a very small corner of AngelCad, my approach mainly being to replicate how i would physically make the objects, and I could no understand why I could not continually alter one object, but had to use intermediaries.

13
I'm wondering if the syntax for the user could be 'improved'. afaik, if I want to create an object with a number of alterations to it, say to represent a plate with a pattern of holes in it, I have to either make multiple objects, either adding them up as I proceed, or at the end, in a return statement, say. The alternative is to create an array, and add the holes there, which seems artificial, to me. Is there not a simpler construction that could be implemented, as in my commented code below, sort of incrementing an object in the similar way we handle other values?


Code: [Select]
// AngelCAD code.

shape@ main_shape()
{
   // create cube and 3 small cubes
   double d = 100;
   solid@ mycub = cube(d);
   solid@ hole = cube(2);
   solid@ holecube1 = mycub - translate(5,10,d-2)*hole;
   solid@ holecube2 = holecube1 -translate(90,5,d-2)*hole;
   solid@ holecube = holecube2 -translate(50,50,d-2)*hole;
 
   return holecube;
}

/*
shape@ main_shape()
{
   // create cube & 3 small cubes - the way I'd like it
   double d = 100;
   solid@ mycub = cube(d);
   solid@ hole = cube(2);
   solid@ holecube = mycub - translate(5,10,d-2)*hole;
   holecube =- translate(90,5,d-2)*hole;
   holecube =- holecube2 -translate(50,50,d-2)*hole;
 
   return holecube;
}

*/
void main()
{
   shape@ obj = main_shape();
   obj.write_xcsg(GetInputFullPath(),secant_tolerance:-1.0);
}

14
General Discussion / Re: rendering of imsges
« on: 2020-09-07, 00:03:31 »
Thanks, I have done that since my first post, but how much longer does it have to be? I suppose the answer is 'long enough'. It could be a problem that the 'long 'hole' could enter a part of the object that you needed it to avoid. It is odd that one hole looks OK, and not the other. In my latest, more complex item, I found it to be very sensitive, overall, in setting the secant_tolerance value. I found if the value was set to give smooth curves, then other parts just disappeared, or generally got messed up.

Anyway, for many parts, it doesn't matter if cylinders are faceted. This very generic handwheel has turned out good enough.

15
General Discussion / Re: rendering of imsges
« on: 2020-09-06, 20:48:11 »
There seems to be a general problem, with cross holes  passing through tubes. depending on the secant_tolerance:value, you do not get the hole, or get a red spot, or if you get the hole, then the tubes are not having a smooth round surface, but a polygon with about ten sides, or the object 'breaks' in other ways. if instead of subtracting, you add, you then get the rod showing correctly. If the edges are viewed, it sort of looks as if the hole is spread over the surface of the cylinder.

Pages: [1] 2 3