discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Re: Where is "path_pos_from_start" in BOLS2 ?

MY
Mr Yura Volodin
Thu, Oct 13, 2022 10:08 AM

Im a bit confused  I think that lookup table are the same as 2d curve with linear interpolation

I have run your code and I have read it through, and as I have said many times it appears WRONG.  Whether I am right about that depends on the exact meaning of pb. 

p = [[0,0],[1,5],[2,100]];
echo(path_pos_from_start(p,path_length(p)/2));
echo(lookup(1,p));

The output is

ECHO: [1, 0.473165]
ECHO: 5

So please tell me the intention.  What do the entries in pb mean exactly?

In my pb coordinates  are swapped.  pb=[[ diam0,length0],[diam1,length1], and so on].I measured diams with a caliper on my brass sax neck. and measured  aproximately length from wider end of neck. As for neck1200.scad   I set test as you suggest::
   pb = [ [50+26.0127,264.979+8],[18,170],[12.3567,0]] ;
When I draw this  with 'stroke' I see two linear line  (see blue line). as I expect.   
   I think the reason you don't end where you expect is probably that you divided by n instead of n+1 in the loop. 

How it can be? beyond the boundaries?
When you use the command place_item(L) is the intention that the item is placed at length L from the end of your model?  Or is the intent that the item is placed somewhere else, approximately L but not exactly L?  Your existing code does the second thing, not the first one. 

As I measure manually there is an error ( estimatly 0.5-1.5mm or more on bented regions) . Second error is of conicity  but the angle is small and I ignore it..
I think difference between exact and approximate  L is within very small region.  

Im a bit confused  I think that lookup table are the same as 2d curve with linear interpolation I have run your code and I have read it through, and as I have said many times it appears WRONG.  Whether I am right about that depends on the exact meaning of pb.  p = [[0,0],[1,5],[2,100]]; echo(path_pos_from_start(p,path_length(p)/2)); echo(lookup(1,p)); The output is ECHO: [1, 0.473165] ECHO: 5 So please tell me the intention.  What do the entries in pb mean exactly? In my pb coordinates  are swapped.  pb=[[ diam0,length0],[diam1,length1], and so on].I measured diams with a caliper on my brass sax neck. and measured  aproximately length from wider end of neck. As for neck1200.scad   I set test as you suggest::    pb = [ [50+26.0127,264.979+8],[18,170],[12.3567,0]] ; When I draw this  with 'stroke' I see two linear line  (see blue line). as I expect.       I think the reason you don't end where you expect is probably that you divided by n instead of n+1 in the loop.  How it can be? beyond the boundaries? When you use the command place_item(L) is the intention that the item is placed at length L from the end of your model?  Or is the intent that the item is placed somewhere else, approximately L but not exactly L?  Your existing code does the second thing, not the first one.  As I measure manually there is an error ( estimatly 0.5-1.5mm or more on bented regions) . Second error is of conicity  but the angle is small and I ignore it.. I think difference between exact and approximate  L is within very small region.  
MY
Mr Yura Volodin
Thu, Oct 13, 2022 10:30 AM

You are right, I made some mistakes,And now 4 variants to choose  from!Your code is excelent, I will play with it 
On Thursday, October 13, 2022 at 01:41:13 AM GMT+3, Adrian Mariano avm4@cornell.edu wrote:

So actually when I said n+1 it should have been n-1.  When I wrote the replacement code I followed your code.  In your code you have this loop:
for (i=[1:1:n-1]){
    diam0= path_pos_from_start(pb,(i-1)bl/n,closed=false);
    diam = path_pos_from_start(pb,i
bl/n,closed=false);
    bt0 = lerp(  pb[diam0[0]],   pb[(diam0[0]+1)%len(pb)],   diam0[1] );
    bt   = lerp(  pb[diam[0]],     pb[(diam[0]+1)%len(pb)],     diam[1]);  
    hull(){  
        path_spread(p, 1,1,bt0[1], rotate_children=true,closed=false) rotate(90,[0,1,0])cylinder(d=bt0[0]+w,h=0.1,$fn=50);
        path_spread(p, 1,1,bt[1], rotate_children=true,closed=false) rotate(90,[0,1,0])cylinder(d=bt[0]+w,h=0.1,$fn=50);
    }
}
The max value of i is n-1.  When you calculate diam you do it at i*bl/n whose max value will be (n-1)*bl/n, or (n-1)/n  * path_length(pb).  That means that you will omit the last sample.  It seems odd, but I was just duplicating the functionality of your code.  As I have said, there are many things that look strange, but only you can say if they are in fact wrong.   It does seem like in most places, the incorrect looking code only makes a small difference in the outcome, like things shift around by less than 1 unit. 

If you want to duplicate the current functionality I still think path_cut is the best way to do it:

module place_item_on_skin(l,angle){
    pathlist = path_cut(pb,l,closed=false);
    pt = last(pathlist[0]);
    echo(equal=pt[1],pl-l);
    color("lightblue") path_spread(p, 1,1,pt[1])
      rotate([90,0,0])translate([0,0,pt[0]/2])children(0);
}

You are right, I made some mistakes,And now 4 variants to choose  from!Your code is excelent, I will play with it  On Thursday, October 13, 2022 at 01:41:13 AM GMT+3, Adrian Mariano <avm4@cornell.edu> wrote: So actually when I said n+1 it should have been n-1.  When I wrote the replacement code I followed your code.  In your code you have this loop: for (i=[1:1:n-1]){     diam0= path_pos_from_start(pb,(i-1)*bl/n,closed=false);     diam = path_pos_from_start(pb,i*bl/n,closed=false);     bt0 = lerp(  pb[diam0[0]],   pb[(diam0[0]+1)%len(pb)],   diam0[1] );     bt   = lerp(  pb[diam[0]],     pb[(diam[0]+1)%len(pb)],     diam[1]);       hull(){           path_spread(p, 1,1,bt0[1], rotate_children=true,closed=false) rotate(90,[0,1,0])cylinder(d=bt0[0]+w,h=0.1,$fn=50);         path_spread(p, 1,1,bt[1], rotate_children=true,closed=false) rotate(90,[0,1,0])cylinder(d=bt[0]+w,h=0.1,$fn=50);     } } The max value of i is n-1.  When you calculate diam you do it at i*bl/n whose max value will be (n-1)*bl/n, or (n-1)/n  * path_length(pb).  That means that you will omit the last sample.  It seems odd, but I was just duplicating the functionality of your code.  As I have said, there are many things that look strange, but only you can say if they are in fact wrong.   It does seem like in most places, the incorrect looking code only makes a small difference in the outcome, like things shift around by less than 1 unit.  If you want to duplicate the current functionality I still think path_cut is the best way to do it: module place_item_on_skin(l,angle){     pathlist = path_cut(pb,l,closed=false);     pt = last(pathlist[0]);     echo(equal=pt[1],pl-l);     color("lightblue") path_spread(p, 1,1,pt[1])       rotate([90,0,0])translate([0,0,pt[0]/2])children(0); }