discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Script to replicate hull and minkoswki for CSG export/import into FreeCAD

AG
Alex Gibson
Wed, Nov 16, 2016 2:06 PM

Looks great!

Thanks – you’ve at least with that helped me understand why what I’m trying to do doesn’t currently export happily from OpenSCAD to Fusion360.

I’m a bit surprised it isn’t a standard feature of Fusion360 – I added a +1 for a now archived feature request for this on the F360 forum – they dropped it for lack of interest!

I may just need to find a different way to achieve the same result in Fusion for 3D hull and Minkowski.

Like you I currently do most things in OpenSCAD, and it’s 100% functional for me – I want to use F360 alongside it to add a more ‘sculpted’ shape to some objects.

An OpenSCAD interpreter for F360 would be amazing, but unlikely to happen.  FreeCAD has this but it’s a shame it’s a bit limited – for 3D printing, I use Minkowski and Hull all the time to ensure corners are cleanly printed…

Cheers

Alex

From: Discuss [mailto:discuss-bounces@lists.openscad.org] On Behalf Of nop head
Sent: 16 November 2016 12:21
To: OpenSCAD general discussion
Subject: Re: [OpenSCAD] Script to replicate hull and minkoswki for CSG export/import into FreeCAD

I recently used the code to model the belt path for an H-bot and calculate its exact length. I modelled the shape of the pitch line (where the cords are) and then offset inwards and outwards to get the belt shape.

The 3D equivalent would be stretching an elastic membrane over spheres with some on the inside and some on the outside. It would be useful but I am not sure I am up to coding it in OpenSCAD. I think the real issue is that FreeCAD needs to support hull and Minkowski. I think OpenSCAD now implements its own versions of those, rather than using CGAL, so perhaps it would be easy to transplant that code into FreeCAD (licenses permitting). I have never used FreeCAD so I am not motivated to do it. OpenSCAD does everything I need.

On 15 November 2016 at 14:34, Alex Gibson alex@alexgibson.net wrote:

Hi Nophead,

Many thanks again for this super useful script back in March.

I have a big request – how would I go about converting this to be a ‘rounded_polygon’ 3d version?

I’m similarly to Ian trying to export an OpenSCAD project to Fusion 360, and find that some fairly straightforward (In Openscad) ‘hull’ functions are hard to recreate.

Or if there’s any other way to replicate the hull() function in Fusion 360 I’d love to know!

Many thanks,

Alex

From: Discuss [mailto:discuss-bounces@lists.openscad.org] On Behalf Of nop head
Sent: 18 March 2016 15:32
To: OpenSCAD general discussion
Subject: Re: [OpenSCAD] Script to replicate hull and minkoswki for CSG export/import into FreeCAD

Cleaned up the generated csg by moving the circle translates inside the if and replaced a call of len(points) with len.

$fn = 100;

shape1 = [ [10, 10, 8], [0, 40, 3], [40, 50, -10], [100, 80, 10], [50, 0, 20] ];

linear_extrude (height = 5) rounded_polygon(shape1);

module rounded_polygon(points)
difference() {
len = len(points);
union() {
for(i = [0 : len - 1])
if(points[i][2] > 0)
translate([points[i].x, points[i].y])
circle(points[i][2]);

        polygon([for(i  = [0 : len - 1]) 
                    let(ends = tangent(points[i], points[(i + 1) % len])) 
                        for(end = [0, 1]) 
                            ends[end]]);
    }
    for(i = [0 : len - 1])
        if(points[i][2] < 0)
            translate([points[i].x, points[i].y])
                circle(-points[i][2]);
 }

function tangent(p1, p2) =
let(
r1 = p1[2],
r2 = p2[2],
dx = p2.x - p1.x,
dy = p2.y - p1.y,
d = sqrt(dx * dx + dy * dy),
theta = atan2(dy, dx) + acos((r1 - r2) / d),
xa = p1.x +(cos(theta) * r1),
ya = p1.y +(sin(theta) * r1),
xb = p2.x +(cos(theta) * r2),
yb = p2.y +(sin(theta) * r2)
)[ [xa, ya], [xb, yb] ];

On 18 March 2016 at 15:20, nop head nop.head@gmail.com wrote:

It calculates the remainder after dividing by the length. That causes the wrap round to zero to close the loop when i+1 equals the length.

On 18 March 2016 at 15:10, droftarts ginjaian@hotmail.com wrote:

Thanks nophead, awesome stuff! I hope you find it useful too. But, dammit,
you're not giving me a chance to use my brain...!

I'll have a sit down over the weekend and see how you've coded this, so I
can understand it. One quick question: you use a '%' sign here:

...
let(ends = tangent(points[i], points[(i + 1) % len(points)]))
...

What does that do? I can see it's a 'scalar arithmetical operator'  (
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Mathematical_Operators )
for modulo (so finds the remainder after division of one number by another),
but I'm not clear why!

Ian S

P.S. re 'Stuart', you addressed me as Stuart in your first post!

--
View this message in context: http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16553.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Looks great! Thanks – you’ve at least with that helped me understand why what I’m trying to do doesn’t currently export happily from OpenSCAD to Fusion360. I’m a bit surprised it isn’t a standard feature of Fusion360 – I added a +1 for a now archived feature request for this on the F360 forum – they dropped it for lack of interest! I may just need to find a different way to achieve the same result in Fusion for 3D hull and Minkowski. Like you I currently do most things in OpenSCAD, and it’s 100% functional for me – I want to use F360 alongside it to add a more ‘sculpted’ shape to some objects. An OpenSCAD interpreter for F360 would be amazing, but unlikely to happen. FreeCAD has this but it’s a shame it’s a bit limited – for 3D printing, I use Minkowski and Hull all the time to ensure corners are cleanly printed… Cheers Alex From: Discuss [mailto:discuss-bounces@lists.openscad.org] On Behalf Of nop head Sent: 16 November 2016 12:21 To: OpenSCAD general discussion Subject: Re: [OpenSCAD] Script to replicate hull and minkoswki for CSG export/import into FreeCAD I recently used the code to model the belt path for an H-bot and calculate its exact length. I modelled the shape of the pitch line (where the cords are) and then offset inwards and outwards to get the belt shape. ​ The 3D equivalent would be stretching an elastic membrane over spheres with some on the inside and some on the outside. It would be useful but I am not sure I am up to coding it in OpenSCAD. I think the real issue is that FreeCAD needs to support hull and Minkowski. I think OpenSCAD now implements its own versions of those, rather than using CGAL, so perhaps it would be easy to transplant that code into FreeCAD (licenses permitting). I have never used FreeCAD so I am not motivated to do it. OpenSCAD does everything I need. On 15 November 2016 at 14:34, Alex Gibson <alex@alexgibson.net> wrote: Hi Nophead, Many thanks again for this super useful script back in March. I have a big request – how would I go about converting this to be a ‘rounded_polygon’ 3d version? I’m similarly to Ian trying to export an OpenSCAD project to Fusion 360, and find that some fairly straightforward (In Openscad) ‘hull’ functions are hard to recreate. Or if there’s any other way to replicate the hull() function in Fusion 360 I’d love to know! Many thanks, Alex From: Discuss [mailto:discuss-bounces@lists.openscad.org] On Behalf Of nop head Sent: 18 March 2016 15:32 To: OpenSCAD general discussion Subject: Re: [OpenSCAD] Script to replicate hull and minkoswki for CSG export/import into FreeCAD Cleaned up the generated csg by moving the circle translates inside the if and replaced a call of len(points) with len. $fn = 100; shape1 = [ [10, 10, 8], [0, 40, 3], [40, 50, -10], [100, 80, 10], [50, 0, 20] ]; linear_extrude (height = 5) rounded_polygon(shape1); module rounded_polygon(points) difference() { len = len(points); union() { for(i = [0 : len - 1]) if(points[i][2] > 0) translate([points[i].x, points[i].y]) circle(points[i][2]); polygon([for(i = [0 : len - 1]) let(ends = tangent(points[i], points[(i + 1) % len])) for(end = [0, 1]) ends[end]]); } for(i = [0 : len - 1]) if(points[i][2] < 0) translate([points[i].x, points[i].y]) circle(-points[i][2]); } function tangent(p1, p2) = let( r1 = p1[2], r2 = p2[2], dx = p2.x - p1.x, dy = p2.y - p1.y, d = sqrt(dx * dx + dy * dy), theta = atan2(dy, dx) + acos((r1 - r2) / d), xa = p1.x +(cos(theta) * r1), ya = p1.y +(sin(theta) * r1), xb = p2.x +(cos(theta) * r2), yb = p2.y +(sin(theta) * r2) )[ [xa, ya], [xb, yb] ]; On 18 March 2016 at 15:20, nop head <nop.head@gmail.com> wrote: It calculates the remainder after dividing by the length. That causes the wrap round to zero to close the loop when i+1 equals the length. On 18 March 2016 at 15:10, droftarts <ginjaian@hotmail.com> wrote: Thanks nophead, awesome stuff! I hope you find it useful too. But, dammit, you're not giving me a chance to use my brain...! I'll have a sit down over the weekend and see how you've coded this, so I can understand it. One quick question: you use a '%' sign here: ... let(ends = tangent(points[i], points[(i + 1) % len(points)])) ... What does that do? I can see it's a 'scalar arithmetical operator' ( https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Mathematical_Operators ) for modulo (so finds the remainder after division of one number by another), but I'm not clear why! Ian S P.S. re 'Stuart', you addressed me as Stuart in your first post! -- View this message in context: http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16553.html Sent from the OpenSCAD mailing list archive at Nabble.com. _______________________________________________ OpenSCAD mailing list Discuss@lists.openscad.org http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org _______________________________________________ OpenSCAD mailing list Discuss@lists.openscad.org http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org