simple BOSL question

classic Classic list List threaded Threaded
24 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: Another BOSL question

adrianv
The problem is that difference() the function returns a region, which is a
list of paths, instead of just a single path, which is a list of points.  It
does this because a difference might contain holes, or disconnected pieces.
If you are sure that your result is a single path you can just extract the
first path on the list, e.g. with difference(...)[0] to get the first path
entry.  That fixes your code below.  

You can also debug things like this using the echo command.  If you do
"echo(Semi());" you'll see that there are extra brackets--though I'll grant
that you need to be looking closely.  Output with echo can be overwhelming
if you generate a lot of points, but you can scale back your point count for
debugging purposes when you don't understand what's going wrong.

Lastly, implementation of boolean operations like difference on paths is a
major technical challenge to implement in OpenSCAD and those operations are
more likely to both run slowly and to possibly fail in unusual cases.   I'd
suggesting using them as the method of last resort.   If you have another
way to generate your object it's probably better to choose that alternative.
In this case, you can make a semicircle using arc(), so that is better.
(But maybe you are working towards something more complex?)  You can also
just cut points out of the point list by using select().  


jon_bondy wrote

> I tried to write a function that returns a list-of-points, but I get
> this error
>
> ERROR: Assertion '(len(bad) == 0)' failed: "Profiles [1] are not a paths
> or have length less than 3", in file
> C:/Users/jon/Documents/OpenSCAD/libraries/BOSL2/skin.scad, line 366
>
> TRACE: called by 'skin' in file
> C:/Users/jon/Documents/OpenSCAD/libraries/BOSL2/skin.scad, line 353
>
> TRACE: called by 'skin' in file Skin Test.scad, line 14
>
>
>
>
> with this code:
>
>
> include <BOSL2/std.scad>
> include <BOSL2/skin.scad>
>
> od = 101.75;
> id = od - 2 * 3.2;
> th = 3;
>
> function Semi() =
>      difference(
>          circle(d = id - 3*th),
>          // cut out just over 1/2
>          move([-990, -500], square(1000)));
>
> skin(
>      [square([2,.2], center=true), Semi()], z=[0,3],
>      slices=40,sampling="length",method="reindex");
>
>
> _______________________________________________
> OpenSCAD mailing list

> Discuss@.openscad

> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org





--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Another BOSL question

RevarBat
This does suggest that we make `skin()` accept regions with exactly one path.

-Revar


> On Jan 5, 2021, at 10:25 AM, adrianv <[hidden email]> wrote:
>
> The problem is that difference() the function returns a region, which is a
> list of paths, instead of just a single path, which is a list of points.  It
> does this because a difference might contain holes, or disconnected pieces.
> If you are sure that your result is a single path you can just extract the
> first path on the list, e.g. with difference(...)[0] to get the first path
> entry.  That fixes your code below.  
>
> You can also debug things like this using the echo command.  If you do
> "echo(Semi());" you'll see that there are extra brackets--though I'll grant
> that you need to be looking closely.  Output with echo can be overwhelming
> if you generate a lot of points, but you can scale back your point count for
> debugging purposes when you don't understand what's going wrong.
>
> Lastly, implementation of boolean operations like difference on paths is a
> major technical challenge to implement in OpenSCAD and those operations are
> more likely to both run slowly and to possibly fail in unusual cases.   I'd
> suggesting using them as the method of last resort.   If you have another
> way to generate your object it's probably better to choose that alternative.
> In this case, you can make a semicircle using arc(), so that is better.
> (But maybe you are working towards something more complex?)  You can also
> just cut points out of the point list by using select().  
>
>
> jon_bondy wrote
>> I tried to write a function that returns a list-of-points, but I get
>> this error
>>
>> ERROR: Assertion '(len(bad) == 0)' failed: "Profiles [1] are not a paths
>> or have length less than 3", in file
>> C:/Users/jon/Documents/OpenSCAD/libraries/BOSL2/skin.scad, line 366
>>
>> TRACE: called by 'skin' in file
>> C:/Users/jon/Documents/OpenSCAD/libraries/BOSL2/skin.scad, line 353
>>
>> TRACE: called by 'skin' in file Skin Test.scad, line 14
>>
>>
>>
>>
>> with this code:
>>
>>
>> include &lt;BOSL2/std.scad&gt;
>> include &lt;BOSL2/skin.scad&gt;
>>
>> od = 101.75;
>> id = od - 2 * 3.2;
>> th = 3;
>>
>> function Semi() =
>>     difference(
>>         circle(d = id - 3*th),
>>         // cut out just over 1/2
>>         move([-990, -500], square(1000)));
>>
>> skin(
>>     [square([2,.2], center=true), Semi()], z=[0,3],
>>     slices=40,sampling="length",method="reindex");
>>
>>
>> _______________________________________________
>> OpenSCAD mailing list
>
>> Discuss@.openscad
>
>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>
>
>
>
>
> --
> Sent from: http://forum.openscad.org/
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Another BOSL question

adrianv
If you want to go there then presumably all functions that take a path should
also take regions with exactly one path.  


RevarBat wrote
> This does suggest that we make `skin()` accept regions with exactly one
> path.
>
> -Revar
>
>
>> On Jan 5, 2021, at 10:25 AM, adrianv &lt;

> avm4@

> &gt; wrote:
>>
>> The problem is that difference() the function returns a region, which is
>> a
>> list of paths, instead of just a single path, which is a list of points.
>> It
>> does this because a difference might contain holes, or disconnected
>> pieces.
>> If you are sure that your result is a single path you can just extract
>> the
>> first path on the list, e.g. with difference(...)[0] to get the first
>> path
>> entry.  That fixes your code below.  
>>
>> You can also debug things like this using the echo command.  If you do
>> "echo(Semi());" you'll see that there are extra brackets--though I'll
>> grant
>> that you need to be looking closely.  Output with echo can be
>> overwhelming
>> if you generate a lot of points, but you can scale back your point count
>> for
>> debugging purposes when you don't understand what's going wrong.
>>
>> Lastly, implementation of boolean operations like difference on paths is
>> a
>> major technical challenge to implement in OpenSCAD and those operations
>> are
>> more likely to both run slowly and to possibly fail in unusual cases.  
>> I'd
>> suggesting using them as the method of last resort.   If you have another
>> way to generate your object it's probably better to choose that
>> alternative.
>> In this case, you can make a semicircle using arc(), so that is better.
>> (But maybe you are working towards something more complex?)  You can also
>> just cut points out of the point list by using select().  
>>
>>
>> jon_bondy wrote
>>> I tried to write a function that returns a list-of-points, but I get
>>> this error
>>>
>>> ERROR: Assertion '(len(bad) == 0)' failed: "Profiles [1] are not a paths
>>> or have length less than 3", in file
>>> C:/Users/jon/Documents/OpenSCAD/libraries/BOSL2/skin.scad, line 366
>>>
>>> TRACE: called by 'skin' in file
>>> C:/Users/jon/Documents/OpenSCAD/libraries/BOSL2/skin.scad, line 353
>>>
>>> TRACE: called by 'skin' in file Skin Test.scad, line 14
>>>
>>>
>>>
>>>
>>> with this code:
>>>
>>>
>>> include &lt;BOSL2/std.scad&gt;
>>> include &lt;BOSL2/skin.scad&gt;
>>>
>>> od = 101.75;
>>> id = od - 2 * 3.2;
>>> th = 3;
>>>
>>> function Semi() =
>>>     difference(
>>>         circle(d = id - 3*th),
>>>         // cut out just over 1/2
>>>         move([-990, -500], square(1000)));
>>>
>>> skin(
>>>     [square([2,.2], center=true), Semi()], z=[0,3],
>>>     slices=40,sampling="length",method="reindex");
>>>
>>>
>>> _______________________________________________
>>> OpenSCAD mailing list
>>
>>> Discuss@.openscad
>>
>>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>>
>>
>>
>>
>>
>> --
>> Sent from: http://forum.openscad.org/
>>
>> _______________________________________________
>> OpenSCAD mailing list
>>

> Discuss@.openscad

>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>
> _______________________________________________
> OpenSCAD mailing list

> Discuss@.openscad

> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org





--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Another BOSL question

jon_bondy
In reply to this post by adrianv
Thank you very much!

Jon

On 1/5/2021 1:25 PM, adrianv wrote:

> The problem is that difference() the function returns a region, which is a
> list of paths, instead of just a single path, which is a list of points.  It
> does this because a difference might contain holes, or disconnected pieces.
> If you are sure that your result is a single path you can just extract the
> first path on the list, e.g. with difference(...)[0] to get the first path
> entry.  That fixes your code below.
>
> You can also debug things like this using the echo command.  If you do
> "echo(Semi());" you'll see that there are extra brackets--though I'll grant
> that you need to be looking closely.  Output with echo can be overwhelming
> if you generate a lot of points, but you can scale back your point count for
> debugging purposes when you don't understand what's going wrong.
>
> Lastly, implementation of boolean operations like difference on paths is a
> major technical challenge to implement in OpenSCAD and those operations are
> more likely to both run slowly and to possibly fail in unusual cases.   I'd
> suggesting using them as the method of last resort.   If you have another
> way to generate your object it's probably better to choose that alternative.
> In this case, you can make a semicircle using arc(), so that is better.
> (But maybe you are working towards something more complex?)  You can also
> just cut points out of the point list by using select().
>
>
> jon_bondy wrote
>> I tried to write a function that returns a list-of-points, but I get
>> this error
>>
>> ERROR: Assertion '(len(bad) == 0)' failed: "Profiles [1] are not a paths
>> or have length less than 3", in file
>> C:/Users/jon/Documents/OpenSCAD/libraries/BOSL2/skin.scad, line 366
>>
>> TRACE: called by 'skin' in file
>> C:/Users/jon/Documents/OpenSCAD/libraries/BOSL2/skin.scad, line 353
>>
>> TRACE: called by 'skin' in file Skin Test.scad, line 14
>>
>>
>>
>>
>> with this code:
>>
>>
>> include &lt;BOSL2/std.scad&gt;
>> include &lt;BOSL2/skin.scad&gt;
>>
>> od = 101.75;
>> id = od - 2 * 3.2;
>> th = 3;
>>
>> function Semi() =
>>       difference(
>>           circle(d = id - 3*th),
>>           // cut out just over 1/2
>>           move([-990, -500], square(1000)));
>>
>> skin(
>>       [square([2,.2], center=true), Semi()], z=[0,3],
>>       slices=40,sampling="length",method="reindex");
>>
>>
>> _______________________________________________
>> OpenSCAD mailing list
>> Discuss@.openscad
>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>
>
>
>
> --
> Sent from: http://forum.openscad.org/
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
12