discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

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

D
droftarts
Mon, Mar 21, 2016 12:15 PM

Neon22 wrote

STEP format import/export is available via:

Its a database kind of format.
In case anyone's interested....

Looks interesting, and it would be great to have output from OpenSCAD that
is more friendly with other CAD packages, that kept the primitive geometry
and parts grouped together. Then it would be easy to export and add
finishing touches eg fillets. But I have no idea if this could be
incorporated into OpenSCAD, and give useful output. Maybe raise it as an
issue on github for the developers to take a look at?

Ian S

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

Neon22 wrote > STEP format import/export is available via: > - PythonOCC (github) > - http://www.pythonocc.org/features_overview/data-exchange/ > - Step people themselves: (github) > - http://stepcode.org/ > > Its a database kind of format. > In case anyone's interested.... Looks interesting, and it would be great to have output from OpenSCAD that is more friendly with other CAD packages, that kept the primitive geometry and parts grouped together. Then it would be easy to export and add finishing touches eg fillets. But I have no idea if this could be incorporated into OpenSCAD, and give useful output. Maybe raise it as an issue on github for the developers to take a look at? Ian S -- View this message in context: http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16628.html Sent from the OpenSCAD mailing list archive at Nabble.com.
DM
doug moen
Mon, Mar 21, 2016 4:34 PM

Producing decent quality STEP output, for the general case, looks like a
complex and challenging project that might require some significant
language extensions. We could also try for simple STEP export, which would
take the CSG tree as input, and fail if any primitives are found that can't
be translated to STEP.

I did a bit of web surfing for this. STEP is a huge standard for encoding
all kinds of manufacturing related data. It's not a file format, it's a
large family of file formats. The particular STEP file format we'd target
is AP203. There's also AP214, which is a superset, but the added features
seem to be things we don't support anyway.

The AP203 definition document is an ISO standard costing 198 swiss franks
(about $200 US). I'd guess you'd need to buy additional standards to
provide the background information for understanding this standard. It
sounds expensive. Another developer cost is purchasing the expensive CAD
programs that read STEP files, like SolidWorks.

I found a database schema for AP203. It appears that AP203 is a large,
complex language for describing geometric solids. It supports splines,
conic curves, meshes, etc. I'm calling it a language because it has
functions like vector cross product.

Anyway, AP203 appears to be a much bigger language than OpenSCAD, but it
also seems to be missing primitives that we support like convex hull and
minkowski sum.

Given how a lot of high level AP203 geometric primitives are coded directly
in OpenSCAD, such as splines and swept volumes, the CSG tree wouldn't be
enough for a good conversion. We'd need the ability to put AP203 metadata
into module definitions to guide the conversion process.

Given the complexity and cost of a good solution, and the limitations and
crappiness of a simple solution, I don't see this as a good fit for the
OpenSCAD project. If someone wants to work on this, I would suggest writing
an external tool for converting CSG files to STEP. Then we'll see.

On 21 March 2016 at 08:15, droftarts ginjaian@hotmail.com wrote:

Neon22 wrote

STEP format import/export is available via:

Its a database kind of format.
In case anyone's interested....

Looks interesting, and it would be great to have output from OpenSCAD that
is more friendly with other CAD packages, that kept the primitive geometry
and parts grouped together. Then it would be easy to export and add
finishing touches eg fillets. But I have no idea if this could be
incorporated into OpenSCAD, and give useful output. Maybe raise it as an
issue on github for the developers to take a look at?

Ian S

--
View this message in context:
http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16628.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

Producing *decent quality* STEP output, for the general case, looks like a complex and challenging project that might require some significant language extensions. We could also try for simple STEP export, which would take the CSG tree as input, and fail if any primitives are found that can't be translated to STEP. I did a bit of web surfing for this. STEP is a huge standard for encoding all kinds of manufacturing related data. It's not a file format, it's a large family of file formats. The particular STEP file format we'd target is AP203. There's also AP214, which is a superset, but the added features seem to be things we don't support anyway. The AP203 definition document is an ISO standard costing 198 swiss franks (about $200 US). I'd guess you'd need to buy additional standards to provide the background information for understanding this standard. It sounds expensive. Another developer cost is purchasing the expensive CAD programs that read STEP files, like SolidWorks. I found a database schema for AP203. It appears that AP203 is a large, complex language for describing geometric solids. It supports splines, conic curves, meshes, etc. I'm calling it a language because it has functions like vector cross product. Anyway, AP203 appears to be a much bigger language than OpenSCAD, but it also seems to be missing primitives that we support like convex hull and minkowski sum. Given how a lot of high level AP203 geometric primitives are coded directly in OpenSCAD, such as splines and swept volumes, the CSG tree wouldn't be enough for a good conversion. We'd need the ability to put AP203 metadata into module definitions to guide the conversion process. Given the complexity and cost of a good solution, and the limitations and crappiness of a simple solution, I don't see this as a good fit for the OpenSCAD project. If someone wants to work on this, I would suggest writing an external tool for converting CSG files to STEP. Then we'll see. On 21 March 2016 at 08:15, droftarts <ginjaian@hotmail.com> wrote: > Neon22 wrote > > STEP format import/export is available via: > > - PythonOCC (github) > > - http://www.pythonocc.org/features_overview/data-exchange/ > > - Step people themselves: (github) > > - http://stepcode.org/ > > > > Its a database kind of format. > > In case anyone's interested.... > > Looks interesting, and it would be great to have output from OpenSCAD that > is more friendly with other CAD packages, that kept the primitive geometry > and parts grouped together. Then it would be easy to export and add > finishing touches eg fillets. But I have no idea if this could be > incorporated into OpenSCAD, and give useful output. Maybe raise it as an > issue on github for the developers to take a look at? > > Ian S > > > > -- > View this message in context: > http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16628.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 > > >
D
droftarts
Mon, Mar 21, 2016 5:27 PM

Many thanks nophead, this works perfectly. It also has a nice feature, that
if you set the radius to '0', it does still work, and produces a 'point'
corner. I guess because the maths in the tangent function ends up = 0 for
the point where the radius = 0. It doesn't even put two points in on the
corner; polygon seems to be smart enough that if you have two point in the
same place, it ignores one of them!

The only improvement might be to error trap any cases where one circle
completely encircles (or is completely inside) the next, or if a
negative-radius circle overlaps a positive one; in both cases the polygon
fails to draw, as there are no tangents that can be calculated, with a
"WARNING: Range check failed for polygon. skipping" message. But maybe this
is actually preferable to ignoring an overlapping circle, and continuing to
draw the shape incorrectly.

Regarding exporting in STEP format, and subsequently opening in CAD software
for rendering: the point is to try and get an assembly of many parts out of
OpenSCAD in one export, where each individual part is separately selectable,
unlike STL ouput. This means that it's easier to apply appearances to
individual parts for rendering, and also it's a better/easier format for
editing in most CAD packages. By using CSG output, there is the additional
advantage of keeping curves and circles as arcs, rather than segmenting
them, which again makes them easier to manipulate in a solid modeller, which
most CAD programs are.

Though CSG exports all the underlying geometry (circles, squares, polygons
etc), once in FreeCAD, only the solid bodies (ie the extrusion based on all
the circles, squares and polygons) are required, not the underlying
geometry, for the STEP file. You can export the simple geometry (most CAD
software suggests building your parts as 2D drawings and extruding to 3D,
which is what the simple geometry is), but I intended the export to be in
one direction, so I don't mind that I remove this geometry. I haven't played
around with Blender much, but I understand it's a 'mesh' modeller, so STL is
a good format for it, and why it doesn't understand what a 'circle' is, let
alone the other OpenSCAD transformations!

A small problem with FreeCAD is that its OpenSCAD import filter needs
updating, as changes in OpenSCAD appear to have caused it to fail if you use
the latest version of OpenSCAD (see
http://forum.freecadweb.org/viewtopic.php?t=12744 ); at least, this is what
it does for me using the current compiled versions of FreeCAD (0.15) and
OpenSCAD (2015.03-2). I don't think this affects importing of CSG files,
just .scad files, and the way FreeCAD imports files is to open the .scad
file in OpenSCAD, and import the .csg file anyway! So I don't think there is
any advantage import the .scad file into FreeCAD (even if you could - it
didn't work when I used OpenSCAD 2014.03 either) over the .csg file.

I based my initial script on circles, rather than squares, as squares are
generally easier to redraw to remove the hull or minkowski command. My
design has rounded corners, so most squares were minkowski'd squares anyway,
which this script can replicate without using minkowski. I know this is
really only a solution for 2D uses of hull and minkowski, and perhaps rather
particular to my intent. I'm not really sure how you could do the same thing
for a 3D object, and get a sensible CSG ouput that you can import into
FreeCAD, to convert to a solid.

Thanks for all the help, hope this is useful to others, too!

Ian S

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

Many thanks nophead, this works perfectly. It also has a nice feature, that if you set the radius to '0', it does still work, and produces a 'point' corner. I guess because the maths in the tangent function ends up = 0 for the point where the radius = 0. It doesn't even put two points in on the corner; polygon seems to be smart enough that if you have two point in the same place, it ignores one of them! The only improvement might be to error trap any cases where one circle completely encircles (or is completely inside) the next, or if a negative-radius circle overlaps a positive one; in both cases the polygon fails to draw, as there are no tangents that can be calculated, with a "WARNING: Range check failed for polygon. skipping" message. But maybe this is actually preferable to ignoring an overlapping circle, and continuing to draw the shape incorrectly. Regarding exporting in STEP format, and subsequently opening in CAD software for rendering: the point is to try and get an assembly of many parts out of OpenSCAD in one export, where each individual part is separately selectable, unlike STL ouput. This means that it's easier to apply appearances to individual parts for rendering, and also it's a better/easier format for editing in most CAD packages. By using CSG output, there is the additional advantage of keeping curves and circles as arcs, rather than segmenting them, which again makes them easier to manipulate in a solid modeller, which most CAD programs are. Though CSG exports all the underlying geometry (circles, squares, polygons etc), once in FreeCAD, only the solid bodies (ie the extrusion based on all the circles, squares and polygons) are required, not the underlying geometry, for the STEP file. You can export the simple geometry (most CAD software suggests building your parts as 2D drawings and extruding to 3D, which is what the simple geometry is), but I intended the export to be in one direction, so I don't mind that I remove this geometry. I haven't played around with Blender much, but I understand it's a 'mesh' modeller, so STL is a good format for it, and why it doesn't understand what a 'circle' is, let alone the other OpenSCAD transformations! A small problem with FreeCAD is that its OpenSCAD import filter needs updating, as changes in OpenSCAD appear to have caused it to fail if you use the latest version of OpenSCAD (see http://forum.freecadweb.org/viewtopic.php?t=12744 ); at least, this is what it does for me using the current compiled versions of FreeCAD (0.15) and OpenSCAD (2015.03-2). I don't think this affects importing of CSG files, just .scad files, and the way FreeCAD imports files is to open the .scad file in OpenSCAD, and import the .csg file anyway! So I don't think there is any advantage import the .scad file into FreeCAD (even if you could - it didn't work when I used OpenSCAD 2014.03 either) over the .csg file. I based my initial script on circles, rather than squares, as squares are generally easier to redraw to remove the hull or minkowski command. My design has rounded corners, so most squares were minkowski'd squares anyway, which this script can replicate without using minkowski. I know this is really only a solution for 2D uses of hull and minkowski, and perhaps rather particular to my intent. I'm not really sure how you could do the same thing for a 3D object, and get a sensible CSG ouput that you can import into FreeCAD, to convert to a solid. Thanks for all the help, hope this is useful to others, too! Ian S -- View this message in context: http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16635.html Sent from the OpenSCAD mailing list archive at Nabble.com.
D
droftarts
Tue, Mar 22, 2016 6:16 PM

I've replaced all the hull and minkowski transformations in my model with the
rounded_polygon script, and exported it from OpenSCAD as a CSG file, which
was then opened in FreeCAD. To export as a STEP file with the 'bodies'
(effectively components) separate (rather than all as one body, so only one
thing is selectable), you need to select each individual body you want in
FreeCAD before exporting as STEP. I don't have too many bodies in my model,
so this wasn't too onerous, only taking a couple of minutes. Then export as
STEP, and open in Fusion 360 (or your CAD program of choice). I didn't try
to do much to the model, just checked that it was editable (it is), then
applied 'appearances' to various bodies. You can also apply appearances to
specific faces. After rendering, I got this, which I'm very happy with:

http://forum.openscad.org/file/n16661/Frame.png

Yes, it's another 3D printer... basically a fully parametric lasercut/CNC
routed/hand cut frame replacement for Mendel/Prusa machines, with minimal
vitamins and no printed parts (so far), and very quick to build. I've
already built a couple of these (admittedly with a standard Prusa i2
x-axis), and they're nice and stiff, and print well (J-head nozzle and
direct drive extruder).

Ian S

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

I've replaced all the hull and minkowski transformations in my model with the rounded_polygon script, and exported it from OpenSCAD as a CSG file, which was then opened in FreeCAD. To export as a STEP file with the 'bodies' (effectively components) separate (rather than all as one body, so only one thing is selectable), you need to select each individual body you want in FreeCAD before exporting as STEP. I don't have too many bodies in my model, so this wasn't too onerous, only taking a couple of minutes. Then export as STEP, and open in Fusion 360 (or your CAD program of choice). I didn't try to do much to the model, just checked that it was editable (it is), then applied 'appearances' to various bodies. You can also apply appearances to specific faces. After rendering, I got this, which I'm very happy with: <http://forum.openscad.org/file/n16661/Frame.png> Yes, it's another 3D printer... basically a fully parametric lasercut/CNC routed/hand cut frame replacement for Mendel/Prusa machines, with minimal vitamins and no printed parts (so far), and very quick to build. I've already built a couple of these (admittedly with a standard Prusa i2 x-axis), and they're nice and stiff, and print well (J-head nozzle and direct drive extruder). Ian S -- View this message in context: http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16661.html Sent from the OpenSCAD mailing list archive at Nabble.com.
NH
nop head
Tue, Mar 22, 2016 6:24 PM

Hard to tell it isn't a photo of a real object. I wish OpenScad could do
that sort of rendering.

On 22 March 2016 at 18:16, droftarts ginjaian@hotmail.com wrote:

I've replaced all the hull and minkowski transformations in my model with
the
rounded_polygon script, and exported it from OpenSCAD as a CSG file, which
was then opened in FreeCAD. To export as a STEP file with the 'bodies'
(effectively components) separate (rather than all as one body, so only one
thing is selectable), you need to select each individual body you want in
FreeCAD before exporting as STEP. I don't have too many bodies in my model,
so this wasn't too onerous, only taking a couple of minutes. Then export as
STEP, and open in Fusion 360 (or your CAD program of choice). I didn't try
to do much to the model, just checked that it was editable (it is), then
applied 'appearances' to various bodies. You can also apply appearances to
specific faces. After rendering, I got this, which I'm very happy with:

http://forum.openscad.org/file/n16661/Frame.png

Yes, it's another 3D printer... basically a fully parametric lasercut/CNC
routed/hand cut frame replacement for Mendel/Prusa machines, with minimal
vitamins and no printed parts (so far), and very quick to build. I've
already built a couple of these (admittedly with a standard Prusa i2
x-axis), and they're nice and stiff, and print well (J-head nozzle and
direct drive extruder).

Ian S

--
View this message in context:
http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16661.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

Hard to tell it isn't a photo of a real object. I wish OpenScad could do that sort of rendering. On 22 March 2016 at 18:16, droftarts <ginjaian@hotmail.com> wrote: > I've replaced all the hull and minkowski transformations in my model with > the > rounded_polygon script, and exported it from OpenSCAD as a CSG file, which > was then opened in FreeCAD. To export as a STEP file with the 'bodies' > (effectively components) separate (rather than all as one body, so only one > thing is selectable), you need to select each individual body you want in > FreeCAD before exporting as STEP. I don't have too many bodies in my model, > so this wasn't too onerous, only taking a couple of minutes. Then export as > STEP, and open in Fusion 360 (or your CAD program of choice). I didn't try > to do much to the model, just checked that it was editable (it is), then > applied 'appearances' to various bodies. You can also apply appearances to > specific faces. After rendering, I got this, which I'm very happy with: > > <http://forum.openscad.org/file/n16661/Frame.png> > > Yes, it's another 3D printer... basically a fully parametric lasercut/CNC > routed/hand cut frame replacement for Mendel/Prusa machines, with minimal > vitamins and no printed parts (so far), and very quick to build. I've > already built a couple of these (admittedly with a standard Prusa i2 > x-axis), and they're nice and stiff, and print well (J-head nozzle and > direct drive extruder). > > Ian S > > > > -- > View this message in context: > http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16661.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 >
D
droftarts
Tue, Mar 22, 2016 7:00 PM

nophead wrote

Hard to tell it isn't a photo of a real object. I wish OpenScad could do
that sort of rendering.

Yes, I'm rather pleased with it! I really didn't have to do very much to the
OpenSCAD output to achieve this, apart from recoding to remove minkowski and
hull. And Fusion 360 is free for 'hobbyists', and is a pretty fully-featured
CAD package.

Many thanks for your help, Chris. I've spoken to you a number of times; I
was the tech support guy at RepRapPro, and also did this thing a while ago,
which I'm in the process of updating with what I've learnt from looking at
the Mendel90 scad files! http://www.thingiverse.com/thing:16627

Ian S

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

nophead wrote > Hard to tell it isn't a photo of a real object. I wish OpenScad could do > that sort of rendering. Yes, I'm rather pleased with it! I really didn't have to do very much to the OpenSCAD output to achieve this, apart from recoding to remove minkowski and hull. And Fusion 360 is free for 'hobbyists', and is a pretty fully-featured CAD package. Many thanks for your help, Chris. I've spoken to you a number of times; I was the tech support guy at RepRapPro, and also did this thing a while ago, which I'm in the process of updating with what I've learnt from looking at the Mendel90 scad files! http://www.thingiverse.com/thing:16627 Ian S -- View this message in context: http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16664.html Sent from the OpenSCAD mailing list archive at Nabble.com.
AG
Alex Gibson
Tue, Mar 22, 2016 8:17 PM

That’s very nice Ian.

Is it rounded_polygon  from Nophead’s  email of 18/03 15:33 you used?

I am keen to recreate your work, but I am a big fan of Minkowski and it’s in most of my printer parts!  However I use my own module to manage it better, so hopefully I can substitute the rounded polygon script or similar without breaking my designs…

By the way, I shipped the first Edumaker prototype today J

Cheers

Alex

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

Hard to tell it isn't a photo of a real object. I wish OpenScad could do that sort of rendering.

On 22 March 2016 at 18:16, droftarts ginjaian@hotmail.com wrote:

I've replaced all the hull and minkowski transformations in my model with the
rounded_polygon script, and exported it from OpenSCAD as a CSG file, which
was then opened in FreeCAD. To export as a STEP file with the 'bodies'
(effectively components) separate (rather than all as one body, so only one
thing is selectable), you need to select each individual body you want in
FreeCAD before exporting as STEP. I don't have too many bodies in my model,
so this wasn't too onerous, only taking a couple of minutes. Then export as
STEP, and open in Fusion 360 (or your CAD program of choice). I didn't try
to do much to the model, just checked that it was editable (it is), then
applied 'appearances' to various bodies. You can also apply appearances to
specific faces. After rendering, I got this, which I'm very happy with:

http://forum.openscad.org/file/n16661/Frame.png

Yes, it's another 3D printer... basically a fully parametric lasercut/CNC
routed/hand cut frame replacement for Mendel/Prusa machines, with minimal
vitamins and no printed parts (so far), and very quick to build. I've
already built a couple of these (admittedly with a standard Prusa i2
x-axis), and they're nice and stiff, and print well (J-head nozzle and
direct drive extruder).

Ian S

--
View this message in context: http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16661.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

That’s very nice Ian. Is it rounded_polygon from Nophead’s email of 18/03 15:33 you used? I am keen to recreate your work, but I am a big fan of Minkowski and it’s in most of my printer parts! However I use my own module to manage it better, so hopefully I can substitute the rounded polygon script or similar without breaking my designs… By the way, I shipped the first Edumaker prototype today J Cheers Alex From: Discuss [mailto:discuss-bounces@lists.openscad.org] On Behalf Of nop head Sent: 22 March 2016 18:25 To: OpenSCAD general discussion Subject: Re: [OpenSCAD] Script to replicate hull and minkoswki for CSG export/import into FreeCAD Hard to tell it isn't a photo of a real object. I wish OpenScad could do that sort of rendering. On 22 March 2016 at 18:16, droftarts <ginjaian@hotmail.com> wrote: I've replaced all the hull and minkowski transformations in my model with the rounded_polygon script, and exported it from OpenSCAD as a CSG file, which was then opened in FreeCAD. To export as a STEP file with the 'bodies' (effectively components) separate (rather than all as one body, so only one thing is selectable), you need to select each individual body you want in FreeCAD before exporting as STEP. I don't have too many bodies in my model, so this wasn't too onerous, only taking a couple of minutes. Then export as STEP, and open in Fusion 360 (or your CAD program of choice). I didn't try to do much to the model, just checked that it was editable (it is), then applied 'appearances' to various bodies. You can also apply appearances to specific faces. After rendering, I got this, which I'm very happy with: <http://forum.openscad.org/file/n16661/Frame.png> Yes, it's another 3D printer... basically a fully parametric lasercut/CNC routed/hand cut frame replacement for Mendel/Prusa machines, with minimal vitamins and no printed parts (so far), and very quick to build. I've already built a couple of these (admittedly with a standard Prusa i2 x-axis), and they're nice and stiff, and print well (J-head nozzle and direct drive extruder). Ian S -- View this message in context: http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16661.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
D
droftarts
Tue, Mar 22, 2016 9:01 PM

alexgibson wrote

That’s very nice Ian. Is it rounded_polygon  from Nophead’s  email of
18/03 15:33 you used?

Yes, I don't think I changed anything from that version. Remember, the
points have to go around in a clockwise direction, though.

alexgibson wrote

By the way, I shipped the first Edumaker prototype today J

Congratulations! I was hoping to catch up with you at rlab last night, as
I'd like to do a coreXY machine using the same construction method as this
machine, but probably with your XY layout (or something similar).

Ian S

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

alexgibson wrote > That’s very nice Ian. Is it rounded_polygon from Nophead’s email of > 18/03 15:33 you used? Yes, I don't think I changed anything from that version. Remember, the points have to go around in a clockwise direction, though. alexgibson wrote > By the way, I shipped the first Edumaker prototype today J Congratulations! I was hoping to catch up with you at rlab last night, as I'd like to do a coreXY machine using the same construction method as this machine, but probably with your XY layout (or something similar). Ian S -- View this message in context: http://forum.openscad.org/Script-to-replicate-hull-and-minkoswki-for-CSG-export-import-into-FreeCAD-tp16537p16669.html Sent from the OpenSCAD mailing list archive at Nabble.com.
AG
Alex Gibson
Tue, Nov 15, 2016 2:34 PM

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

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
NH
nop head
Wed, Nov 16, 2016 12:21 PM

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

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 > >