Open nichtich opened 12 years ago
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:
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.
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
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?
Just curious if there is any progress on this?
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 d_length+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.
@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.
OpenSCAD rocks, but the lack of a line() function is killing it for 2D usage. I have a beautiful 2D parametric design I want to cut on the laser but all my "lines" are really rectangles and come out in the DXF as double lines after they get merged with other such "lines". This is problematic because it means laser cutting the same line twice. When I try to migrate to a die for die cutting, this is a show stopper because the die manufacturer can't take the OpenSCAD DXF. I love OpenSCAD but this needs to be fixed!
The issue is that OpenSCAD models 2D objects not laser tool paths. If you were using the result to CNC route something you would pass the DXF that describes the object to a CAM program to get the tool path to make it. The CAM program would subtract the kerf.
Because the kerf with a laser is very small there seems to be a tradition of leaving out the CAM stage and just using the object's outlines as the tool path.
When you have a line the laser actually cuts a slot. If you modelled an object with a slot at kerf width and passed it through a laser CAM program it could reduce it to a single line down the middle. The problem is I don't think there are any CAM programs for lasers.
Maybe try Rapcad? It's an (old) fork of OpenSCAD that includes a polyline primitive. I haven't tried it, but it looks like DXF export is now supported.
+1 on this. Would love to be able to use this for laser cutting, but without line, it's really difficult.
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:
is equivalent to
and to
But when you do cutting, you might want to have two pieces:
For 2D modeling there should be a command to create unfilled
outline
s from objects and a command to create unclosedline
s (I'd also likebezier
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.