discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Re: Where is "path_pos_from_start" in BOLS2 ?

AM
Adrian Mariano
Wed, Oct 12, 2022 10:47 AM

When you invoke path_pos_from_start() on the pb variable you are treating
pb as a curve in 2d.  But from reading your code, it appears that pb is NOT
a curve in 2d.  It is a lookup table that specifies the diameter as a
function of path length along the curve defined by p.  I am somewhat
guessing here based on the code, but if that is true, then treating it like
a curve in 2D will give incorrect results.  If we have a simple example:

p=
[[0,0],
[1,5],
[2,100]]

where the first entry gives position and the second entry gives diameter
then the correct diameter at the midpoint, position 1, is 5, but if you use
the method implemented in the neck1000 code which is based on path length,
so path_pos_from_start(p,path_length(p)/2) you get a diameter of 0.47
instead of 5.  You can't assume that the functions will magically produce
the right answer even if you ask them to do the wrong thing!

Interpolating a 2d curve, which is what path_pos_from_start (and path_cut)
do is not the same as interpolating a lookup table.  A correct way to get
that value would be lookup(1,p);  I think you can replace every call of
path_pos_from_start with lookup and then you won't need the old function.

On Wed, Oct 12, 2022 at 3:34 AM Mr Yura Volodin via Discuss <
discuss@lists.openscad.org> wrote:

---------- Forwarded message ----------
From: Mr Yura Volodin yur_vol@yahoo.com
To: OpenSCAD general discussion Mailing-list discuss@lists.openscad.org
Cc:
Bcc:
Date: Wed, 12 Oct 2022 07:33:15 +0000 (UTC)
Subject: [OpenSCAD] Re: Where is "path_pos_from_start" in BOLS2 ?
As I understand interpolation is done automatically inside the BOLS2
functions.  Dont know what exactly method is implemented.
You set number of equally spaced interpolation points only for generating
tube. It does not depend from how input path set.
So you can find a point at given length.
For tangent/normal rotating items I set rotate_children=true

On Wednesday, October 12, 2022 at 02:00:39 AM GMT+3, Adrian Mariano <
avm4@cornell.edu> wrote:

I examined neck1200.scad.  The problem reported about errors compiling is
fixed by removing the "use" statements.

However, I'm a little confused about the intent of the neck1200 code.
There is a list of points in 2d described as "diameter".  It appears that
maybe the second value is the position and the first value the diameter at
that position.  This point list is then operated on using
path_pos_from_start.  But that doesn't make sense, because the data is not
actually a path in 2d.  You should be interpolating just on the second
coordinate to find position.  I would probably do this with lookup()----but
the coordinates would need to be swapped first.

The code for creating the actual shape is a chain hull of cylinders.  I
would do this with sweep.  I would use path_sweep with the transforms=true
option to get a list of transform matrices.  I would apply the scales to
those and then invoke sweep().

For putting objects on the surface you should be able to do it with just a
call to path_spread(), I think.  Note that path_cut is not a drop in
replacement for path_pos_from_start().  The old function returned an index
into the path plus a fraction along the next path segment.  The new
function takes a list of cut points and returns all the paths cut at those
points, so you can then extract the ends that you need directly.

Docs for path_cut:
https://github.com/revarbat/BOSL2/wiki/paths.scad#function-path_cut

If you just want the code to work, here's the old function:

function path_pos_from_start(path,length,closed=false,_d=0,_i=0) =
let (lp = len(path))
_i >= lp - (closed?0:1)? undef :
let (l = norm(path[(_i+1)%lp]-path[_i]))
_d+l <= length? path_pos_from_start(path,length,closed,_d+l,_i+1) :
[_i, (length-_d)/l];

On Tue, Oct 11, 2022 at 5:02 AM Mr Yura Volodin via Discuss <
discuss@lists.openscad.org> wrote:

---------- Forwarded message ----------
From: Mr Yura Volodin yur_vol@yahoo.com
To: OpenSCAD general discussion Mailing-list discuss@lists.openscad.org
Cc:
Bcc:
Date: Tue, 11 Oct 2022 09:01:36 +0000 (UTC)
Subject: [OpenSCAD] Re: Where is "path_pos_from_start" in BOLS2 ?
Direct replacement does not work. see attachment

More info:
To reverse engineering saxophones for fdm 3dprinting  I use two curve
approach.
One curve is path to "extrude" and second is - diameters along this path.
After bulding tube I place toneholes, posts and etc, defined by length
from top of tube.
So I need function to return diameter at given length and angle to rotate
item I want to place
I draw curve manually in MOI3D then save as polyline dxf then convert to
openscad polyline with dxfwread.exe tool.
I almost solved all the above, but have a feel that there is more elegant
solution.

Equal spacing along the curve is overkill on straight segments. BSpline
examples in this maillist seems to be useful but I didnot realize how to
implement.
I still didnot understand why length of the resulting tube depends from
quantization number and how to avoid its changing.

On Tuesday, October 11, 2022 at 12:55:06 AM GMT+3, Adrian Mariano <
avm4@cornell.edu> wrote:

I believe that path_pos_from_start was eliminated because it was redundant
with path_cut.  Can path_cut do what you need?

On Mon, Oct 10, 2022 at 11:56 AM Mr Yura Volodin via Discuss <
discuss@lists.openscad.org> wrote:

---------- Forwarded message ----------
From: Mr Yura Volodin yur_vol@yahoo.com
To: Mr Yura Volodin via Discuss discuss@lists.openscad.org
Cc:
Bcc:
Date: Mon, 10 Oct 2022 15:55:25 +0000 (UTC)
Subject: [OpenSCAD] Where is "path_pos_from_start"  in BOLS2 ?
I use this function in BOLS2 from 2020 for finding point  to place an item
on curved tube.
It is absent in newer BOLS2.
What I need to use insteed ?

SY, Yuri

---------- Forwarded message ----------
From: Mr Yura Volodin via Discuss discuss@lists.openscad.org
To: Mr Yura Volodin via Discuss discuss@lists.openscad.org
Cc: Mr Yura Volodin yur_vol@yahoo.com
Bcc:
Date: Mon, 10 Oct 2022 15:55:25 +0000 (UTC)
Subject: [OpenSCAD] Where is "path_pos_from_start"  in BOLS2 ?


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

---------- Forwarded message ----------
From: Mr Yura Volodin via Discuss discuss@lists.openscad.org
To: OpenSCAD general discussion Mailing-list discuss@lists.openscad.org
Cc: Mr Yura Volodin yur_vol@yahoo.com
Bcc:
Date: Tue, 11 Oct 2022 09:01:36 +0000 (UTC)
Subject: [OpenSCAD] Re: Where is "path_pos_from_start" in BOLS2 ?


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

---------- Forwarded message ----------
From: Mr Yura Volodin via Discuss discuss@lists.openscad.org
To: OpenSCAD general discussion Mailing-list discuss@lists.openscad.org
Cc: Mr Yura Volodin yur_vol@yahoo.com
Bcc:
Date: Wed, 12 Oct 2022 07:33:15 +0000 (UTC)
Subject: [OpenSCAD] Re: Where is "path_pos_from_start" in BOLS2 ?


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

When you invoke path_pos_from_start() on the pb variable you are treating pb as a curve in 2d. But from reading your code, it appears that pb is NOT a curve in 2d. It is a lookup table that specifies the diameter as a function of path length along the curve defined by p. I am somewhat guessing here based on the code, but if that is true, then treating it like a curve in 2D will give incorrect results. If we have a simple example: p= [[0,0], [1,5], [2,100]] where the first entry gives position and the second entry gives diameter then the correct diameter at the midpoint, position 1, is 5, but if you use the method implemented in the neck1000 code which is based on path length, so path_pos_from_start(p,path_length(p)/2) you get a diameter of 0.47 instead of 5. You can't assume that the functions will magically produce the right answer even if you ask them to do the wrong thing! Interpolating a 2d curve, which is what path_pos_from_start (and path_cut) do is not the same as interpolating a lookup table. A correct way to get that value would be lookup(1,p); I think you can replace every call of path_pos_from_start with lookup and then you won't need the old function. On Wed, Oct 12, 2022 at 3:34 AM Mr Yura Volodin via Discuss < discuss@lists.openscad.org> wrote: > > > > ---------- Forwarded message ---------- > From: Mr Yura Volodin <yur_vol@yahoo.com> > To: OpenSCAD general discussion Mailing-list <discuss@lists.openscad.org> > Cc: > Bcc: > Date: Wed, 12 Oct 2022 07:33:15 +0000 (UTC) > Subject: [OpenSCAD] Re: Where is "path_pos_from_start" in BOLS2 ? > As I understand interpolation is done automatically inside the BOLS2 > functions. Dont know what exactly method is implemented. > You set number of equally spaced interpolation points only for generating > tube. It does not depend from how input path set. > So you can find a point at given length. > For tangent/normal rotating items I set rotate_children=true > > >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > On Wednesday, October 12, 2022 at 02:00:39 AM GMT+3, Adrian Mariano < > avm4@cornell.edu> wrote: > > > I examined neck1200.scad. The problem reported about errors compiling is > fixed by removing the "use" statements. > > However, I'm a little confused about the intent of the neck1200 code. > There is a list of points in 2d described as "diameter". It appears that > maybe the second value is the position and the first value the diameter at > that position. This point list is then operated on using > path_pos_from_start. But that doesn't make sense, because the data is not > actually a path in 2d. You should be interpolating just on the second > coordinate to find position. I would probably do this with lookup()----but > the coordinates would need to be swapped first. > > The code for creating the actual shape is a chain hull of cylinders. I > would do this with sweep. I would use path_sweep with the transforms=true > option to get a list of transform matrices. I would apply the scales to > those and then invoke sweep(). > > For putting objects on the surface you should be able to do it with just a > call to path_spread(), I think. Note that path_cut is not a drop in > replacement for path_pos_from_start(). The old function returned an index > into the path plus a fraction along the next path segment. The new > function takes a list of cut points and returns all the paths cut at those > points, so you can then extract the ends that you need directly. > > Docs for path_cut: > https://github.com/revarbat/BOSL2/wiki/paths.scad#function-path_cut > > If you just want the code to work, here's the old function: > > function path_pos_from_start(path,length,closed=false,_d=0,_i=0) = > let (lp = len(path)) > _i >= lp - (closed?0:1)? undef : > let (l = norm(path[(_i+1)%lp]-path[_i])) > _d+l <= length? path_pos_from_start(path,length,closed,_d+l,_i+1) : > [_i, (length-_d)/l]; > > On Tue, Oct 11, 2022 at 5:02 AM Mr Yura Volodin via Discuss < > discuss@lists.openscad.org> wrote: > > > > > ---------- Forwarded message ---------- > From: Mr Yura Volodin <yur_vol@yahoo.com> > To: OpenSCAD general discussion Mailing-list <discuss@lists.openscad.org> > Cc: > Bcc: > Date: Tue, 11 Oct 2022 09:01:36 +0000 (UTC) > Subject: [OpenSCAD] Re: Where is "path_pos_from_start" in BOLS2 ? > Direct replacement does not work. see attachment > > More info: > To reverse engineering saxophones for fdm 3dprinting I use two curve > approach. > One curve is path to "extrude" and second is - diameters along this path. > After bulding tube I place toneholes, posts and etc, defined by length > from top of tube. > So I need function to return diameter at given length and angle to rotate > item I want to place > I draw curve manually in MOI3D then save as polyline dxf then convert to > openscad polyline with dxfwread.exe tool. > I almost solved all the above, but have a feel that there is more elegant > solution. > > Equal spacing along the curve is overkill on straight segments. BSpline > examples in this maillist seems to be useful but I didnot realize how to > implement. > I still didnot understand why length of the resulting tube depends from > quantization number and how to avoid its changing. > > > > > > >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > > On Tuesday, October 11, 2022 at 12:55:06 AM GMT+3, Adrian Mariano < > avm4@cornell.edu> wrote: > > > I believe that path_pos_from_start was eliminated because it was redundant > with path_cut. Can path_cut do what you need? > > On Mon, Oct 10, 2022 at 11:56 AM Mr Yura Volodin via Discuss < > discuss@lists.openscad.org> wrote: > > > > > ---------- Forwarded message ---------- > From: Mr Yura Volodin <yur_vol@yahoo.com> > To: Mr Yura Volodin via Discuss <discuss@lists.openscad.org> > Cc: > Bcc: > Date: Mon, 10 Oct 2022 15:55:25 +0000 (UTC) > Subject: [OpenSCAD] Where is "path_pos_from_start" in BOLS2 ? > I use this function in BOLS2 from 2020 for finding point to place an item > on curved tube. > It is absent in newer BOLS2. > What I need to use insteed ? > > SY, Yuri > > > > ---------- Forwarded message ---------- > From: Mr Yura Volodin via Discuss <discuss@lists.openscad.org> > To: Mr Yura Volodin via Discuss <discuss@lists.openscad.org> > Cc: Mr Yura Volodin <yur_vol@yahoo.com> > Bcc: > Date: Mon, 10 Oct 2022 15:55:25 +0000 (UTC) > Subject: [OpenSCAD] Where is "path_pos_from_start" in BOLS2 ? > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org > > > > ---------- Forwarded message ---------- > From: Mr Yura Volodin via Discuss <discuss@lists.openscad.org> > To: OpenSCAD general discussion Mailing-list <discuss@lists.openscad.org> > Cc: Mr Yura Volodin <yur_vol@yahoo.com> > Bcc: > Date: Tue, 11 Oct 2022 09:01:36 +0000 (UTC) > Subject: [OpenSCAD] Re: Where is "path_pos_from_start" in BOLS2 ? > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org > > > > ---------- Forwarded message ---------- > From: Mr Yura Volodin via Discuss <discuss@lists.openscad.org> > To: OpenSCAD general discussion Mailing-list <discuss@lists.openscad.org> > Cc: Mr Yura Volodin <yur_vol@yahoo.com> > Bcc: > Date: Wed, 12 Oct 2022 07:33:15 +0000 (UTC) > Subject: [OpenSCAD] Re: Where is "path_pos_from_start" in BOLS2 ? > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
MY
Mr Yura Volodin
Wed, Oct 12, 2022 12:03 PM

I tried your idea but don't get 0.47. It still seems linear interpolatetion here.Please run my code with old paths.scad I attached. It's working code.
On Wednesday, October 12, 2022 at 01:47:51 PM GMT+3, Adrian Mariano avm4@cornell.edu wrote:

When you invoke path_pos_from_start() on the pb variable you are treating pb as a curve in 2d.  But from reading your code, it appears that pb is NOT a curve in 2d.  It is a lookup table that specifies the diameter as a function of path length along the curve defined by p.  I am somewhat guessing here based on the code, but if that is true, then treating it like a curve in 2D will give incorrect results.  If we have a simple example:
p=
[[0,0], [1,5], [2,100]]
where the first entry gives position and the second entry gives diameter then the correct diameter at the midpoint, position 1, is 5, but if you use the method implemented in the neck1000 code which is based on path length, so path_pos_from_start(p,path_length(p)/2) you get a diameter of 0.47 instead of 5.  You can't assume that the functions will magically produce the right answer even if you ask them to do the wrong thing!
Interpolating a 2d curve, which is what path_pos_from_start (and path_cut) do is not the same as interpolating a lookup table.  A correct way to get that value would be lookup(1,p);  I think you can replace every call of path_pos_from_start with lookup and then you won't need the old function. 

On Wed, Oct 12, 2022 at 3:34 AM Mr Yura Volodin via Discuss discuss@lists.openscad.org wrote:

---------- Forwarded message ----------
From: Mr Yura Volodin yur_vol@yahoo.com
To: OpenSCAD general discussion Mailing-list discuss@lists.openscad.org
Cc: 
Bcc: 
Date: Wed, 12 Oct 2022 07:33:15 +0000 (UTC)
Subject: [OpenSCAD] Re: Where is "path_pos_from_start" in BOLS2 ?
As I understand interpolation is done automatically inside the BOLS2 functions.  Dont know what exactly method is implemented.
You set number of equally spaced interpolation points only for generating tube. It does not depend from how input path set.So you can find a point at given length.
For tangent/normal rotating items I set rotate_children=true

On Wednesday, October 12, 2022 at 02:00:39 AM GMT+3, Adrian Mariano <avm4@cornell.edu> wrote:  

I examined neck1200.scad.  The problem reported about errors compiling is fixed by removing the "use" statements. 

However, I'm a little confused about the intent of the neck1200 code.  There is a list of points in 2d described as "diameter".  It appears that maybe the second value is the position and the first value the diameter at that position.  This point list is then operated on using path_pos_from_start.  But that doesn't make sense, because the data is not actually a path in 2d.  You should be interpolating just on the second coordinate to find position.  I would probably do this with lookup()----but the coordinates would need to be swapped first.
The code for creating the actual shape is a chain hull of cylinders.  I would do this with sweep.  I would use path_sweep with the transforms=true option to get a list of transform matrices.  I would apply the scales to those and then invoke sweep(). 

For putting objects on the surface you should be able to do it with just a call to path_spread(), I think.  Note that path_cut is not a drop in replacement for path_pos_from_start().  The old function returned an index into the path plus a fraction along the next path segment.  The new function takes a list of cut points and returns all the paths cut at those points, so you can then extract the ends that you need directly. 

Docs for path_cut:
https://github.com/revarbat/BOSL2/wiki/paths.scad#function-path_cut
If you just want the code to work, here's the old function:
function path_pos_from_start(path,length,closed=false,_d=0,_i=0) =
    let (lp = len(path))
    _i >= lp - (closed?0:1)? undef :
    let (l = norm(path[(_i+1)%lp]-path[_i]))
    _d+l <= length? path_pos_from_start(path,length,closed,_d+l,_i+1) :
    [_i, (length-_d)/l];

On Tue, Oct 11, 2022 at 5:02 AM Mr Yura Volodin via Discuss discuss@lists.openscad.org wrote:

---------- Forwarded message ----------
From: Mr Yura Volodin yur_vol@yahoo.com
To: OpenSCAD general discussion Mailing-list discuss@lists.openscad.org
Cc: 
Bcc: 
Date: Tue, 11 Oct 2022 09:01:36 +0000 (UTC)
Subject: [OpenSCAD] Re: Where is "path_pos_from_start" in BOLS2 ?
Direct replacement does not work. see attachment

More info:To reverse engineering saxophones for fdm 3dprinting  I use two curve approach.One curve is path to "extrude" and second is - diameters along this path.After bulding tube I place toneholes, posts and etc, defined by length from top of tube.So I need function to return diameter at given length and angle to rotate item I want to placeI draw curve manually in MOI3D then save as polyline dxf then convert to openscad polyline with dxfwread.exe tool.I almost solved all the above, but have a feel that there is more elegant solution.
Equal spacing along the curve is overkill on straight segments. BSpline examples in this maillist seems to be useful but I didnot realize how to implement.I still didnot understand why length of the resulting tube depends from quantization number and how to avoid its changing.
 

On Tuesday, October 11, 2022 at 12:55:06 AM GMT+3, Adrian Mariano <avm4@cornell.edu> wrote:  

I believe that path_pos_from_start was eliminated because it was redundant with path_cut.  Can path_cut do what you need? 

On Mon, Oct 10, 2022 at 11:56 AM Mr Yura Volodin via Discuss discuss@lists.openscad.org wrote:

---------- Forwarded message ----------
From: Mr Yura Volodin yur_vol@yahoo.com
To: Mr Yura Volodin via Discuss discuss@lists.openscad.org
Cc: 
Bcc: 
Date: Mon, 10 Oct 2022 15:55:25 +0000 (UTC)
Subject: [OpenSCAD] Where is "path_pos_from_start"  in BOLS2 ?
I use this function in BOLS2 from 2020 for finding point  to place an item on curved tube.It is absent in newer BOLS2.
What I need to use insteed ?
SY, Yuri

---------- Forwarded message ----------
From: Mr Yura Volodin via Discuss discuss@lists.openscad.org
To: Mr Yura Volodin via Discuss discuss@lists.openscad.org
Cc: Mr Yura Volodin yur_vol@yahoo.com
Bcc: 
Date: Mon, 10 Oct 2022 15:55:25 +0000 (UTC)
Subject: [OpenSCAD] Where is "path_pos_from_start"  in BOLS2 ?


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

---------- Forwarded message ----------
From: Mr Yura Volodin via Discuss discuss@lists.openscad.org
To: OpenSCAD general discussion Mailing-list discuss@lists.openscad.org
Cc: Mr Yura Volodin yur_vol@yahoo.com
Bcc: 
Date: Tue, 11 Oct 2022 09:01:36 +0000 (UTC)
Subject: [OpenSCAD] Re: Where is "path_pos_from_start" in BOLS2 ?


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

---------- Forwarded message ----------
From: Mr Yura Volodin via Discuss discuss@lists.openscad.org
To: OpenSCAD general discussion Mailing-list discuss@lists.openscad.org
Cc: Mr Yura Volodin yur_vol@yahoo.com
Bcc: 
Date: Wed, 12 Oct 2022 07:33:15 +0000 (UTC)
Subject: [OpenSCAD] Re: Where is "path_pos_from_start" in BOLS2 ?


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

I tried your idea but don't get 0.47. It still seems linear interpolatetion here.Please run my code with old paths.scad I attached. It's working code. On Wednesday, October 12, 2022 at 01:47:51 PM GMT+3, Adrian Mariano <avm4@cornell.edu> wrote: When you invoke path_pos_from_start() on the pb variable you are treating pb as a curve in 2d.  But from reading your code, it appears that pb is NOT a curve in 2d.  It is a lookup table that specifies the diameter as a function of path length along the curve defined by p.  I am somewhat guessing here based on the code, but if that is true, then treating it like a curve in 2D will give incorrect results.  If we have a simple example: p= [[0,0], [1,5], [2,100]] where the first entry gives position and the second entry gives diameter then the correct diameter at the midpoint, position 1, is 5, but if you use the method implemented in the neck1000 code which is based on path length, so path_pos_from_start(p,path_length(p)/2) you get a diameter of 0.47 instead of 5.  You can't assume that the functions will magically produce the right answer even if you ask them to do the wrong thing! Interpolating a 2d curve, which is what path_pos_from_start (and path_cut) do is not the same as interpolating a lookup table.  A correct way to get that value would be lookup(1,p);  I think you can replace every call of path_pos_from_start with lookup and then you won't need the old function.  On Wed, Oct 12, 2022 at 3:34 AM Mr Yura Volodin via Discuss <discuss@lists.openscad.org> wrote: ---------- Forwarded message ---------- From: Mr Yura Volodin <yur_vol@yahoo.com> To: OpenSCAD general discussion Mailing-list <discuss@lists.openscad.org> Cc:  Bcc:  Date: Wed, 12 Oct 2022 07:33:15 +0000 (UTC) Subject: [OpenSCAD] Re: Where is "path_pos_from_start" in BOLS2 ? As I understand interpolation is done automatically inside the BOLS2 functions.  Dont know what exactly method is implemented. You set number of equally spaced interpolation points only for generating tube. It does not depend from how input path set.So you can find a point at given length. For tangent/normal rotating items I set rotate_children=true >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> On Wednesday, October 12, 2022 at 02:00:39 AM GMT+3, Adrian Mariano <avm4@cornell.edu> wrote: I examined neck1200.scad.  The problem reported about errors compiling is fixed by removing the "use" statements.  However, I'm a little confused about the intent of the neck1200 code.  There is a list of points in 2d described as "diameter".  It appears that maybe the second value is the position and the first value the diameter at that position.  This point list is then operated on using path_pos_from_start.  But that doesn't make sense, because the data is not actually a path in 2d.  You should be interpolating just on the second coordinate to find position.  I would probably do this with lookup()----but the coordinates would need to be swapped first. The code for creating the actual shape is a chain hull of cylinders.  I would do this with sweep.  I would use path_sweep with the transforms=true option to get a list of transform matrices.  I would apply the scales to those and then invoke sweep().  For putting objects on the surface you should be able to do it with just a call to path_spread(), I think.  Note that path_cut is not a drop in replacement for path_pos_from_start().  The old function returned an index into the path plus a fraction along the next path segment.  The new function takes a list of cut points and returns all the paths cut at those points, so you can then extract the ends that you need directly.  Docs for path_cut: https://github.com/revarbat/BOSL2/wiki/paths.scad#function-path_cut If you just want the code to work, here's the old function: function path_pos_from_start(path,length,closed=false,_d=0,_i=0) =     let (lp = len(path))     _i >= lp - (closed?0:1)? undef :     let (l = norm(path[(_i+1)%lp]-path[_i]))     _d+l <= length? path_pos_from_start(path,length,closed,_d+l,_i+1) :     [_i, (length-_d)/l]; On Tue, Oct 11, 2022 at 5:02 AM Mr Yura Volodin via Discuss <discuss@lists.openscad.org> wrote: ---------- Forwarded message ---------- From: Mr Yura Volodin <yur_vol@yahoo.com> To: OpenSCAD general discussion Mailing-list <discuss@lists.openscad.org> Cc:  Bcc:  Date: Tue, 11 Oct 2022 09:01:36 +0000 (UTC) Subject: [OpenSCAD] Re: Where is "path_pos_from_start" in BOLS2 ? Direct replacement does not work. see attachment More info:To reverse engineering saxophones for fdm 3dprinting  I use two curve approach.One curve is path to "extrude" and second is - diameters along this path.After bulding tube I place toneholes, posts and etc, defined by length from top of tube.So I need function to return diameter at given length and angle to rotate item I want to placeI draw curve manually in MOI3D then save as polyline dxf then convert to openscad polyline with dxfwread.exe tool.I almost solved all the above, but have a feel that there is more elegant solution. Equal spacing along the curve is overkill on straight segments. BSpline examples in this maillist seems to be useful but I didnot realize how to implement.I still didnot understand why length of the resulting tube depends from quantization number and how to avoid its changing.   >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> On Tuesday, October 11, 2022 at 12:55:06 AM GMT+3, Adrian Mariano <avm4@cornell.edu> wrote: I believe that path_pos_from_start was eliminated because it was redundant with path_cut.  Can path_cut do what you need?  On Mon, Oct 10, 2022 at 11:56 AM Mr Yura Volodin via Discuss <discuss@lists.openscad.org> wrote: ---------- Forwarded message ---------- From: Mr Yura Volodin <yur_vol@yahoo.com> To: Mr Yura Volodin via Discuss <discuss@lists.openscad.org> Cc:  Bcc:  Date: Mon, 10 Oct 2022 15:55:25 +0000 (UTC) Subject: [OpenSCAD] Where is "path_pos_from_start"  in BOLS2 ? I use this function in BOLS2 from 2020 for finding point  to place an item on curved tube.It is absent in newer BOLS2. What I need to use insteed ? SY, Yuri ---------- Forwarded message ---------- From: Mr Yura Volodin via Discuss <discuss@lists.openscad.org> To: Mr Yura Volodin via Discuss <discuss@lists.openscad.org> Cc: Mr Yura Volodin <yur_vol@yahoo.com> Bcc:  Date: Mon, 10 Oct 2022 15:55:25 +0000 (UTC) Subject: [OpenSCAD] Where is "path_pos_from_start"  in BOLS2 ? _______________________________________________ OpenSCAD mailing list To unsubscribe send an email to discuss-leave@lists.openscad.org _______________________________________________ OpenSCAD mailing list To unsubscribe send an email to discuss-leave@lists.openscad.org ---------- Forwarded message ---------- From: Mr Yura Volodin via Discuss <discuss@lists.openscad.org> To: OpenSCAD general discussion Mailing-list <discuss@lists.openscad.org> Cc: Mr Yura Volodin <yur_vol@yahoo.com> Bcc:  Date: Tue, 11 Oct 2022 09:01:36 +0000 (UTC) Subject: [OpenSCAD] Re: Where is "path_pos_from_start" in BOLS2 ? _______________________________________________ OpenSCAD mailing list To unsubscribe send an email to discuss-leave@lists.openscad.org _______________________________________________ OpenSCAD mailing list To unsubscribe send an email to discuss-leave@lists.openscad.org ---------- Forwarded message ---------- From: Mr Yura Volodin via Discuss <discuss@lists.openscad.org> To: OpenSCAD general discussion Mailing-list <discuss@lists.openscad.org> Cc: Mr Yura Volodin <yur_vol@yahoo.com> Bcc:  Date: Wed, 12 Oct 2022 07:33:15 +0000 (UTC) Subject: [OpenSCAD] Re: Where is "path_pos_from_start" in BOLS2 ? _______________________________________________ OpenSCAD mailing list To unsubscribe send an email to discuss-leave@lists.openscad.org _______________________________________________ OpenSCAD mailing list To unsubscribe send an email to discuss-leave@lists.openscad.org
MY
Mr Yura Volodin
Wed, Oct 12, 2022 6:02 PM

I modified my code with your solution.on github
Thank you very much for solution.I modified my code and it works.To place item at given length I must to resample at needed pecision.If 1mm is enough I use   module place_item(l,angle){       pbr = resample_path(pb, ceil(path_length(pb)+1), closed=false);      path_spread(p, 1,1,pbr[l][1] ) rotate([90,0,0]) children(0);    }
I attached new code. 
Now I am trying to undestand why my tube does not start at 0,0 of the path and why it stopped at points depending of NSee attached pic.

On Wednesday, October 12, 2022 at 01:47:51 PM GMT+3, Adrian Mariano <avm4@cornell.edu> wrote:  

When you invoke path_pos_from_start() on the pb variable you are treating pb as a curve in 2d.  But from reading your code, it appears that pb is NOT a curve in 2d.  It is a lookup table that specifies the diameter as a function of path length along the curve defined by p.  I am somewhat guessing here based on the code, but if that is true, then treating it like a curve in 2D will give incorrect results.  If we have a simple example:
p=
[[0,0], [1,5], [2,100]]
where the first entry gives position and the second entry gives diameter then the correct diameter at the midpoint, position 1, is 5, but if you use the method implemented in the neck1000 code which is based on path length, so path_pos_from_start(p,path_length(p)/2) you get a diameter of 0.47 instead of 5.  You can't assume that the functions will magically produce the right answer even if you ask them to do the wrong thing!
Interpolating a 2d curve, which is what path_pos_from_start (and path_cut) do is not the same as interpolating a lookup table.  A correct way to get that value would be lookup(1,p);  I think you can replace every call of path_pos_from_start with lookup and then you won't need the old function. 

On Wed, Oct 12, 2022 at 3:34 AM Mr Yura Volodin via Discuss discuss@lists.openscad.org wrote:

---------- Forwarded message ----------
From: Mr Yura Volodin yur_vol@yahoo.com
To: OpenSCAD general discussion Mailing-list discuss@lists.openscad.org
Cc: 
Bcc: 
Date: Wed, 12 Oct 2022 07:33:15 +0000 (UTC)
Subject: [OpenSCAD] Re: Where is "path_pos_from_start" in BOLS2 ?
As I understand interpolation is done automatically inside the BOLS2 functions.  Dont know what exactly method is implemented.
You set number of equally spaced interpolation points only for generating tube. It does not depend from how input path set.So you can find a point at given length.
For tangent/normal rotating items I set rotate_children=true

On Wednesday, October 12, 2022 at 02:00:39 AM GMT+3, Adrian Mariano <avm4@cornell.edu> wrote:  

I examined neck1200.scad.  The problem reported about errors compiling is fixed by removing the "use" statements. 

However, I'm a little confused about the intent of the neck1200 code.  There is a list of points in 2d described as "diameter".  It appears that maybe the second value is the position and the first value the diameter at that position.  This point list is then operated on using path_pos_from_start.  But that doesn't make sense, because the data is not actually a path in 2d.  You should be interpolating just on the second coordinate to find position.  I would probably do this with lookup()----but the coordinates would need to be swapped first.
The code for creating the actual shape is a chain hull of cylinders.  I would do this with sweep.  I would use path_sweep with the transforms=true option to get a list of transform matrices.  I would apply the scales to those and then invoke sweep(). 

For putting objects on the surface you should be able to do it with just a call to path_spread(), I think.  Note that path_cut is not a drop in replacement for path_pos_from_start().  The old function returned an index into the path plus a fraction along the next path segment.  The new function takes a list of cut points and returns all the paths cut at those points, so you can then extract the ends that you need directly. 

Docs for path_cut:
https://github.com/revarbat/BOSL2/wiki/paths.scad#function-path_cut
If you just want the code to work, here's the old function:
function path_pos_from_start(path,length,closed=false,_d=0,_i=0) =
    let (lp = len(path))
    _i >= lp - (closed?0:1)? undef :
    let (l = norm(path[(_i+1)%lp]-path[_i]))
    _d+l <= length? path_pos_from_start(path,length,closed,_d+l,_i+1) :
    [_i, (length-_d)/l];

On Tue, Oct 11, 2022 at 5:02 AM Mr Yura Volodin via Discuss discuss@lists.openscad.org wrote:

---------- Forwarded message ----------
From: Mr Yura Volodin yur_vol@yahoo.com
To: OpenSCAD general discussion Mailing-list discuss@lists.openscad.org
Cc: 
Bcc: 
Date: Tue, 11 Oct 2022 09:01:36 +0000 (UTC)
Subject: [OpenSCAD] Re: Where is "path_pos_from_start" in BOLS2 ?
Direct replacement does not work. see attachment

More info:To reverse engineering saxophones for fdm 3dprinting  I use two curve approach.One curve is path to "extrude" and second is - diameters along this path.After bulding tube I place toneholes, posts and etc, defined by length from top of tube.So I need function to return diameter at given length and angle to rotate item I want to placeI draw curve manually in MOI3D then save as polyline dxf then convert to openscad polyline with dxfwread.exe tool.I almost solved all the above, but have a feel that there is more elegant solution.
Equal spacing along the curve is overkill on straight segments. BSpline examples in this maillist seems to be useful but I didnot realize how to implement.I still didnot understand why length of the resulting tube depends from quantization number and how to avoid its changing.
 

On Tuesday, October 11, 2022 at 12:55:06 AM GMT+3, Adrian Mariano <avm4@cornell.edu> wrote:  

I believe that path_pos_from_start was eliminated because it was redundant with path_cut.  Can path_cut do what you need? 

On Mon, Oct 10, 2022 at 11:56 AM Mr Yura Volodin via Discuss discuss@lists.openscad.org wrote:

---------- Forwarded message ----------
From: Mr Yura Volodin yur_vol@yahoo.com
To: Mr Yura Volodin via Discuss discuss@lists.openscad.org
Cc: 
Bcc: 
Date: Mon, 10 Oct 2022 15:55:25 +0000 (UTC)
Subject: [OpenSCAD] Where is "path_pos_from_start"  in BOLS2 ?
I use this function in BOLS2 from 2020 for finding point  to place an item on curved tube.It is absent in newer BOLS2.
What I need to use insteed ?
SY, Yuri

---------- Forwarded message ----------
From: Mr Yura Volodin via Discuss discuss@lists.openscad.org
To: Mr Yura Volodin via Discuss discuss@lists.openscad.org
Cc: Mr Yura Volodin yur_vol@yahoo.com
Bcc: 
Date: Mon, 10 Oct 2022 15:55:25 +0000 (UTC)
Subject: [OpenSCAD] Where is "path_pos_from_start"  in BOLS2 ?


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

---------- Forwarded message ----------
From: Mr Yura Volodin via Discuss discuss@lists.openscad.org
To: OpenSCAD general discussion Mailing-list discuss@lists.openscad.org
Cc: Mr Yura Volodin yur_vol@yahoo.com
Bcc: 
Date: Tue, 11 Oct 2022 09:01:36 +0000 (UTC)
Subject: [OpenSCAD] Re: Where is "path_pos_from_start" in BOLS2 ?


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

---------- Forwarded message ----------
From: Mr Yura Volodin via Discuss discuss@lists.openscad.org
To: OpenSCAD general discussion Mailing-list discuss@lists.openscad.org
Cc: Mr Yura Volodin yur_vol@yahoo.com
Bcc: 
Date: Wed, 12 Oct 2022 07:33:15 +0000 (UTC)
Subject: [OpenSCAD] Re: Where is "path_pos_from_start" in BOLS2 ?


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

I modified my code with your solution.on github Thank you very much for solution.I modified my code and it works.To place item at given length I must to resample at needed pecision.If 1mm is enough I use   module place_item(l,angle){       pbr = resample_path(pb, ceil(path_length(pb)+1), closed=false);      path_spread(p, 1,1,pbr[l][1] ) rotate([90,0,0]) children(0);    } I attached new code.  Now I am trying to undestand why my tube does not start at 0,0 of the path and why it stopped at points depending of NSee attached pic. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> On Wednesday, October 12, 2022 at 01:47:51 PM GMT+3, Adrian Mariano <avm4@cornell.edu> wrote: When you invoke path_pos_from_start() on the pb variable you are treating pb as a curve in 2d.  But from reading your code, it appears that pb is NOT a curve in 2d.  It is a lookup table that specifies the diameter as a function of path length along the curve defined by p.  I am somewhat guessing here based on the code, but if that is true, then treating it like a curve in 2D will give incorrect results.  If we have a simple example: p= [[0,0], [1,5], [2,100]] where the first entry gives position and the second entry gives diameter then the correct diameter at the midpoint, position 1, is 5, but if you use the method implemented in the neck1000 code which is based on path length, so path_pos_from_start(p,path_length(p)/2) you get a diameter of 0.47 instead of 5.  You can't assume that the functions will magically produce the right answer even if you ask them to do the wrong thing! Interpolating a 2d curve, which is what path_pos_from_start (and path_cut) do is not the same as interpolating a lookup table.  A correct way to get that value would be lookup(1,p);  I think you can replace every call of path_pos_from_start with lookup and then you won't need the old function.  On Wed, Oct 12, 2022 at 3:34 AM Mr Yura Volodin via Discuss <discuss@lists.openscad.org> wrote: ---------- Forwarded message ---------- From: Mr Yura Volodin <yur_vol@yahoo.com> To: OpenSCAD general discussion Mailing-list <discuss@lists.openscad.org> Cc:  Bcc:  Date: Wed, 12 Oct 2022 07:33:15 +0000 (UTC) Subject: [OpenSCAD] Re: Where is "path_pos_from_start" in BOLS2 ? As I understand interpolation is done automatically inside the BOLS2 functions.  Dont know what exactly method is implemented. You set number of equally spaced interpolation points only for generating tube. It does not depend from how input path set.So you can find a point at given length. For tangent/normal rotating items I set rotate_children=true >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> On Wednesday, October 12, 2022 at 02:00:39 AM GMT+3, Adrian Mariano <avm4@cornell.edu> wrote: I examined neck1200.scad.  The problem reported about errors compiling is fixed by removing the "use" statements.  However, I'm a little confused about the intent of the neck1200 code.  There is a list of points in 2d described as "diameter".  It appears that maybe the second value is the position and the first value the diameter at that position.  This point list is then operated on using path_pos_from_start.  But that doesn't make sense, because the data is not actually a path in 2d.  You should be interpolating just on the second coordinate to find position.  I would probably do this with lookup()----but the coordinates would need to be swapped first. The code for creating the actual shape is a chain hull of cylinders.  I would do this with sweep.  I would use path_sweep with the transforms=true option to get a list of transform matrices.  I would apply the scales to those and then invoke sweep().  For putting objects on the surface you should be able to do it with just a call to path_spread(), I think.  Note that path_cut is not a drop in replacement for path_pos_from_start().  The old function returned an index into the path plus a fraction along the next path segment.  The new function takes a list of cut points and returns all the paths cut at those points, so you can then extract the ends that you need directly.  Docs for path_cut: https://github.com/revarbat/BOSL2/wiki/paths.scad#function-path_cut If you just want the code to work, here's the old function: function path_pos_from_start(path,length,closed=false,_d=0,_i=0) =     let (lp = len(path))     _i >= lp - (closed?0:1)? undef :     let (l = norm(path[(_i+1)%lp]-path[_i]))     _d+l <= length? path_pos_from_start(path,length,closed,_d+l,_i+1) :     [_i, (length-_d)/l]; On Tue, Oct 11, 2022 at 5:02 AM Mr Yura Volodin via Discuss <discuss@lists.openscad.org> wrote: ---------- Forwarded message ---------- From: Mr Yura Volodin <yur_vol@yahoo.com> To: OpenSCAD general discussion Mailing-list <discuss@lists.openscad.org> Cc:  Bcc:  Date: Tue, 11 Oct 2022 09:01:36 +0000 (UTC) Subject: [OpenSCAD] Re: Where is "path_pos_from_start" in BOLS2 ? Direct replacement does not work. see attachment More info:To reverse engineering saxophones for fdm 3dprinting  I use two curve approach.One curve is path to "extrude" and second is - diameters along this path.After bulding tube I place toneholes, posts and etc, defined by length from top of tube.So I need function to return diameter at given length and angle to rotate item I want to placeI draw curve manually in MOI3D then save as polyline dxf then convert to openscad polyline with dxfwread.exe tool.I almost solved all the above, but have a feel that there is more elegant solution. Equal spacing along the curve is overkill on straight segments. BSpline examples in this maillist seems to be useful but I didnot realize how to implement.I still didnot understand why length of the resulting tube depends from quantization number and how to avoid its changing.   >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> On Tuesday, October 11, 2022 at 12:55:06 AM GMT+3, Adrian Mariano <avm4@cornell.edu> wrote: I believe that path_pos_from_start was eliminated because it was redundant with path_cut.  Can path_cut do what you need?  On Mon, Oct 10, 2022 at 11:56 AM Mr Yura Volodin via Discuss <discuss@lists.openscad.org> wrote: ---------- Forwarded message ---------- From: Mr Yura Volodin <yur_vol@yahoo.com> To: Mr Yura Volodin via Discuss <discuss@lists.openscad.org> Cc:  Bcc:  Date: Mon, 10 Oct 2022 15:55:25 +0000 (UTC) Subject: [OpenSCAD] Where is "path_pos_from_start"  in BOLS2 ? I use this function in BOLS2 from 2020 for finding point  to place an item on curved tube.It is absent in newer BOLS2. What I need to use insteed ? SY, Yuri ---------- Forwarded message ---------- From: Mr Yura Volodin via Discuss <discuss@lists.openscad.org> To: Mr Yura Volodin via Discuss <discuss@lists.openscad.org> Cc: Mr Yura Volodin <yur_vol@yahoo.com> Bcc:  Date: Mon, 10 Oct 2022 15:55:25 +0000 (UTC) Subject: [OpenSCAD] Where is "path_pos_from_start"  in BOLS2 ? _______________________________________________ OpenSCAD mailing list To unsubscribe send an email to discuss-leave@lists.openscad.org _______________________________________________ OpenSCAD mailing list To unsubscribe send an email to discuss-leave@lists.openscad.org ---------- Forwarded message ---------- From: Mr Yura Volodin via Discuss <discuss@lists.openscad.org> To: OpenSCAD general discussion Mailing-list <discuss@lists.openscad.org> Cc: Mr Yura Volodin <yur_vol@yahoo.com> Bcc:  Date: Tue, 11 Oct 2022 09:01:36 +0000 (UTC) Subject: [OpenSCAD] Re: Where is "path_pos_from_start" in BOLS2 ? _______________________________________________ OpenSCAD mailing list To unsubscribe send an email to discuss-leave@lists.openscad.org _______________________________________________ OpenSCAD mailing list To unsubscribe send an email to discuss-leave@lists.openscad.org ---------- Forwarded message ---------- From: Mr Yura Volodin via Discuss <discuss@lists.openscad.org> To: OpenSCAD general discussion Mailing-list <discuss@lists.openscad.org> Cc: Mr Yura Volodin <yur_vol@yahoo.com> Bcc:  Date: Wed, 12 Oct 2022 07:33:15 +0000 (UTC) Subject: [OpenSCAD] Re: Where is "path_pos_from_start" in BOLS2 ? _______________________________________________ OpenSCAD mailing list To unsubscribe send an email to discuss-leave@lists.openscad.org _______________________________________________ OpenSCAD mailing list To unsubscribe send an email to discuss-leave@lists.openscad.org