Skip to content

Better support 2D models by adding lines #99

Open
nichtich opened this Issue Mar 5, 2012 · 7 comments

7 participants

@nichtich
nichtich commented Mar 5, 2012

2D laser cutting and CNC is not hyped as much as 3D printing, but it has similar potential. Although OpenSCAD has been designed for 3D modeling, you can also use it to create some flat 2D models, which can be exported as DXF files (I'd prefer an SVG export, but that's another issue).

However there is one problem: There are no simple lines in OpenSCAD! Objects that tough each other are always joined by UNION so you cannot cut them into pieces. Here is an example:

square([10,10]); translate([0,5]) circle(5);

is equivalent to

union() { square([10,10]); translate([0,5]) circle(5); }

and to

group() { square([10,10]); translate([0,5]) circle(5); }

But when you do cutting, you might want to have two pieces:

difference() { square([10,10]); translate([0,5]) circle(5); } // one
translate([0,5]) circle(5); // second

For 2D modeling there should be a command to create unfilled outlines from objects and a command to create unclosed lines (I'd also like bezier to draw Bezier lines but that's another issue). Outlines and lines are closed or unclosed lines in space that can also be unioned and differenced. For 3D models, simple lines should not harm, they can be used as guidelines for visualizing, but just ignored in the STL export. However, for serious 2D models we need simple lines as elements in OpenSCAD and DXF/SVG export.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@donbright
openscad member

I believe that something like this may be possible with CGAL. Specifically, the "Nef Poylhedrons" used by CGAL can create 'open' line segments.

The following example from the CGAL documentation demonstrates the representation of an 'antenna' poking out of a cube.

http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Nef_3/Chapter_main.html#Subsection_28.7.2

From what I understand, these '1 dimensional' shapes can be intersectioned, unioned, differenced, etc - they are just Nef Polyhedron objects like any other.

I am guessing if you started to implement this, the problem might be that OpenSCAD's guts are built around the idea of whole, closed shapes, not 2d lines. There might be some interesting bugs and crashes if you feed non-closed shapes through some of OpenSCAD's inner machinery.

A good part of OpenSCAD's inner workings use the CGAL conversion from CGAL's Nef Polyhedron to CGAL's 'Polyhedron3'. Conversion to STL for example. A Polyhedron3, however, has to be 'closed', aka "orientable 2-manifold objects with boundaries". I.e. no line segments poking around everywhere. If it's not closed, the conversion barfs. Or OpenSCAD barfs because it checks 'is_simple()' or some such before conversion to check if the Nef Polyhedron has any weird features that are not "orientable 2-manifoled objects with boundaries". The CGAL conversion process is described here:

http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Nef_3/Chapter_main.html#Subsection_28.5.4

So, how do you do the conversion and just 'drop' your line segments? As far as I know, CGAL will not do this 'drop' for you. OpenSCAD would probably need to be smart enough to figure out how to 'drop' the line segments from the Nef Polyhedron3 before feeding them to these conversion routines (like STL). That could mean, for example, possibly iterating through the Nef Polyhedron and 'trimming' everything that looks like a line segment. I'm not sure how difficult that would be. . .

I don't think it's impossible, but I think it is a few dozen hours of work (at least for some slow person like me).


PS... I know you requested 2d, not 3d... but IMHO the same principles apply. CGAL's implementation of Nef Polyhedron is similar whether you are talking 3d or 2d and i think the solutions will be similar too.


note to self:

http://www.cadkas.de/downengcad4font2dxf.php

http://www.mrrace.com/CamBam_Fonts/

@GilesBathgate

Its certainly possible to create unclosed lines with CGAL, I have a polyline() module in rapcad that does this. Its not very useful by itself but it can be combined with minkowski to do a glide like operation. ultimately print paths and lazer cutter paths can be represented by polylines, and of course they would be exportable to dxf when I implement that too.

@nichtich
nichtich commented Mar 6, 2012

Looks like polyline() can do 2d lines, I will have a look at repcad - is it just a better fork of openscad?

P.S: If OpenSCAD is based on GCAL, it should be listed at http://www.cgal.org/projects.html

@bkorsedal

I have a similar issue.

I want to build some shade structures in my front yard for a garden. I'm building them out of PVC piping. I want to bend and twist it all funky.

I want to CAD it up in OpenSCAD first, so I'm trying to create a function I like to call Bezier_Noodle. It's a pipe curved to match a quadratic bezier equation. Anyway, I'm trying to do it as a bunch of cylinder segments, but getting the rotation is difficult. It would be soooooooo much easier to do a polyline minkowski with a cylinder, but no lines in OpenSCAD.

What did you guys end up doing with your problems?

@peteruithoven

Just curious if there is any progress on this?

@ksa-real

Note that this problem exists for 3d shapes as well. I recently created parametric bearing.
http://www.thingiverse.com/thing:396232
It would be a way easier to create polygon in a loop than trying to unite polygons. Also as (d+1)length is not guaranteed to be the same as dlength+length, I had to use tolerance for sectors to match up. (which is not known etc). So I had to use hacks to implement this.

@t-paul
openscad member
t-paul commented Jul 17, 2014

@ksa-real generating polygons / polyhedrons by calculating the points is possible in the dev-snapshots, for example like function circle(r) = [for (a=[0:360/$fn:360-360/$fn]) [r * sin(a), r * cos(a), 0]]; from https://gist.github.com/kintel/4645e2c91eb02e577688 which has more complex examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.