discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

How to build a path from module?

YV
yur_vol@yahoo.com
Fri, Apr 24, 2026 1:03 PM

I experimented with method of finding central curve between two curves.
I used rolling circle approach.
But cannot realize how to build path from or convert my code to function.

// OpenSCAD script
include <BOSL2/std.scad>
include <BOSL2/paths.scad>
path1_ =  turtle([
"setdir",[ 0.9999628439258978 , 0.008620369344191262 ],
"move", 131.61920759666071 ,
"arcright", 457.311530035779 , 11.113083250909 ,
"arcright", 230.376137082125 , 10.956953223018004 ,
"arcright", 160.66912568929 , 18.450652801659984 
]);
path2_ =  turtle([
//"setdir",[ 0.008144659602120722 , -0.9999668317099151 ],
//"move", 69.65338256607936 ,
"setdir",[ 0.9999457509425375 , 0.01041610157231193 ],
"move", 54.46405137254055 ,
"arcright", 550.553241146635 , 12.694511790404007 ,
"arcright", 180.059997747103 , 14.684664978003 ,
"arcright", 44.239827893159 , 26.04640755017499 ,
"setdir",[ 0.6041990084225062 , -0.7968334570167472 ],
"move", 9.584902834836015 ,
],state=[0,-69.65338256607936]);
n=30;
path1 = resample_path(path1_, n=n,closed=false);
path2 = resample_path(path2_, n=n,closed=false);
stroke(path1);
stroke(path2);
centers=(path2+path1)/2;
stroke(centers); // rough method
normals = path_normals(path1,closed=false);
for(j=[0:len(normals)-1]){        
        for (r=[1:0.5:60]){           
           pt = path1[j]+normals[j]*r;
           closest = path_closest_point(path2, pt);
           delta=path_length([path1[j],pt])- path_length([closest[1],pt]);
           if (abs(delta)<0.5){
               color("blue") translate(pt) circle(d=2, $fn=12);
           ;}
        }
     }
//a=[];     
//function cnt(a)=[
//    for(j=[0:len(normals)-1])        
//        for (r=[1:0.5:60]){           
//           pt = path1[j]+normals[j]*r;
//           closest = path_closest_point(path2, pt);
//           delta=path_length([path1[j],pt])- path_length([closest[1],pt]);
//           a=abs(delta)<0.5?pt:[];                 
//           }
//        }     
//];

I experimented with method of finding central curve between two curves.\ I used rolling circle approach.\ But cannot realize how to build path from or convert my code to function. ``` // OpenSCAD script ``` ``` include <BOSL2/std.scad> ``` ``` include <BOSL2/paths.scad> ``` ``` path1_ = turtle([ ``` ``` "setdir",[ 0.9999628439258978 , 0.008620369344191262 ], ``` ``` "move", 131.61920759666071 , ``` ``` "arcright", 457.311530035779 , 11.113083250909 , ``` ``` "arcright", 230.376137082125 , 10.956953223018004 , ``` ``` "arcright", 160.66912568929 , 18.450652801659984 ``` ``` ]); ``` ``` path2_ = turtle([ ``` ``` //"setdir",[ 0.008144659602120722 , -0.9999668317099151 ], ``` ``` //"move", 69.65338256607936 , ``` ``` "setdir",[ 0.9999457509425375 , 0.01041610157231193 ], ``` ``` "move", 54.46405137254055 , ``` ``` "arcright", 550.553241146635 , 12.694511790404007 , ``` ``` "arcright", 180.059997747103 , 14.684664978003 , ``` ``` "arcright", 44.239827893159 , 26.04640755017499 , ``` ``` "setdir",[ 0.6041990084225062 , -0.7968334570167472 ], ``` ``` "move", 9.584902834836015 , ``` ``` ],state=[0,-69.65338256607936]); ``` ``` n=30; ``` ``` path1 = resample_path(path1_, n=n,closed=false); ``` ``` path2 = resample_path(path2_, n=n,closed=false); ``` ``` stroke(path1); ``` ``` stroke(path2); ``` ``` centers=(path2+path1)/2; ``` ``` stroke(centers); // rough method ``` ``` normals = path_normals(path1,closed=false); ``` ``` for(j=[0:len(normals)-1]){ ``` ``` for (r=[1:0.5:60]){ ``` ``` pt = path1[j]+normals[j]*r; ``` ``` closest = path_closest_point(path2, pt); ``` ``` delta=path_length([path1[j],pt])- path_length([closest[1],pt]); ``` ``` if (abs(delta)<0.5){ ``` ``` color("blue") translate(pt) circle(d=2, $fn=12); ``` ``` ;} ``` ``` } ``` ``` } ``` ``` //a=[]; ``` ``` //function cnt(a)=[ ``` ``` // for(j=[0:len(normals)-1]) ``` ``` // for (r=[1:0.5:60]){ ``` ``` // pt = path1[j]+normals[j]*r; ``` ``` // closest = path_closest_point(path2, pt); ``` ``` // delta=path_length([path1[j],pt])- path_length([closest[1],pt]); ``` ``` // a=abs(delta)<0.5?pt:[]; ``` ``` // } ``` ``` // } ``` ``` //]; ```
JB
Jordan Brown
Fri, Apr 24, 2026 9:13 PM

I think that BOSL2 paths are just lists of coordinates.  Try echo()ing
one to confirm.

If so, just build up such a list.  You're already doing that; you just
need to turn your loops into a list comprehension.

Totally untested, but something like

|path = [ for(j=[0:len(normals)-1], r=[1:0.5:60]) let( pt =
path1[j]+normals[j]*r, closest = path_closest_point(path2, pt),
delta=path_length([path1[j],pt])- path_length([closest[1],pt]) ) if
(abs(delta)<0.5) pt ];|

I think that BOSL2 paths are just lists of coordinates.  Try echo()ing one to confirm. If so, just build up such a list.  You're already doing that; you just need to turn your loops into a list comprehension. Totally untested, but something like |path = [ for(j=[0:len(normals)-1], r=[1:0.5:60]) let( pt = path1[j]+normals[j]*r, closest = path_closest_point(path2, pt), delta=path_length([path1[j],pt])- path_length([closest[1],pt]) ) if (abs(delta)<0.5) pt ];|
YV
yur_vol@yahoo.com
Mon, Apr 27, 2026 7:03 AM

Excellent!
Exactly what I need.
using let in loop

Excellent!\ Exactly what I need.\ using let in loop