discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Combining polyhedrons to make a solid

N
NathanA
Sat, Dec 27, 2014 6:16 PM

Is it possible to combine 2D objects to make a solid? I have some complex
polyhedrons that combine, with all faces facing outwards, to make a solid.
However, they don't show in F6. Strangely, a single polyhedron will show in
F6, even though it is not solid, but when the edge coincides with another
polyhedron they both disappear. Here is a simple example of a cube made out
of two polyhedrons:

polyhedron(
points=[ [0,0,0],[10,0,0],[10,0,10],[0,0,10],
[0,10,0],[0,10,10],
[10,10,10],[10,10,0]
],                                // the apex point
faces=[[0,3,2,1,0], [0,4,5,3],[5,4,7,6,5],[1,2,6,7,1],
[0,1,7,4,0]
]
);
polyhedron(
points=[ [0,0,10],[0,10,10],[10,10,10],[10,0,10]
],                                // the apex point
faces=[[0,1,2,3,0]]
);

--
View this message in context: http://forum.openscad.org/Combining-polyhedrons-to-make-a-solid-tp10750.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Is it possible to combine 2D objects to make a solid? I have some complex polyhedrons that combine, with all faces facing outwards, to make a solid. However, they don't show in F6. Strangely, a single polyhedron will show in F6, even though it is not solid, but when the edge coincides with another polyhedron they both disappear. Here is a simple example of a cube made out of two polyhedrons: polyhedron( points=[ [0,0,0],[10,0,0],[10,0,10],[0,0,10], [0,10,0],[0,10,10], [10,10,10],[10,10,0] ], // the apex point faces=[[0,3,2,1,0], [0,4,5,3],[5,4,7,6,5],[1,2,6,7,1], [0,1,7,4,0] ] ); polyhedron( points=[ [0,0,10],[0,10,10],[10,10,10],[10,0,10] ], // the apex point faces=[[0,1,2,3,0]] ); -- View this message in context: http://forum.openscad.org/Combining-polyhedrons-to-make-a-solid-tp10750.html Sent from the OpenSCAD mailing list archive at Nabble.com.
B
Bananapeel
Sat, Dec 27, 2014 6:39 PM

Wikipedia: "In elementary geometry, a polyhedron (plural polyhedra or
polyhedrons) is a solid in three dimensions with flat faces, straight edges
and sharp corners or vertices."

Both of your polyhedrons are actually invalid (they aren't solids), which is
why it doesn't work.

--
View this message in context: http://forum.openscad.org/Combining-polyhedrons-to-make-a-solid-tp10750p10752.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Wikipedia: "In elementary geometry, a polyhedron (plural polyhedra or polyhedrons) is a solid in three dimensions with flat faces, straight edges and sharp corners or vertices." Both of your polyhedrons are actually invalid (they aren't solids), which is why it doesn't work. -- View this message in context: http://forum.openscad.org/Combining-polyhedrons-to-make-a-solid-tp10750p10752.html Sent from the OpenSCAD mailing list archive at Nabble.com.
N
NathanA
Sat, Dec 27, 2014 7:21 PM

Ok, so I was afraid of that. The problem arises if you want to create a 3D
object, made of many individual 2D polyhedron parts that is only solid when
all the parts are combined. Creating one huge polyhedron would create a huge
list of points and point references in the faces. Designing and
troubleshooting that can be a nightmare. Editing it would be even worse
since all the face references might need to be adjusted.

To address this I created a function to combine multiple individual
polyhedrons into one large polyhedron. This way all the point references in
the individual polyhedron faces will only reference their own points. In
case anyone else has the same issue here is my function. Below is the simple
example from above created from two separate [point, faces] lists. Each
polyhedron can be rendered separately while designing (try it by using
polyhedron(points=poly1[0], faces=poly1[1]) but is combined to make the
final solid. This does F6!

//input is a list of [points, faces]
//For each faces, increment the point references by the previous number of
points
function combine_polyhedrons(list, points=[], faces=[], point_count=0, i=0)

i < len(list) ? 
    combine_polyhedrons(list,
        concat(points, list[i][0]),
        concat(faces, [for (face_i = [0:len(list[i][1])-1])
            [for (point_i = [0:len(list[i][1][face_i])-1]) 
                list[i][1][face_i][point_i] + point_count]]),
        point_count + len(list[i][0]),
        i + 1)
    : [points, faces];
        

//Each poly is [points, faces]
poly1 = [[ [0,0,0],[10,0,0],[10,0,10],[0,0,10],
[0,10,0],[0,10,10],[10,10,10],[10,10,0]
],
[ [0,3,2,1,0], [0,4,5,3],[5,4,7,6,5],[1,2,6,7,1], [0,1,7,4,0] ]
];
poly2 = [[ [0,0,10],[0,10,10],[10,10,10],[10,0,10] ],
[ [0,1,2,3,0] ]
];

new_polyhendron = combine_polyhedrons([poly1, poly2]);
polyhedron(points=new_polyhendron[0], faces=new_polyhendron[1]);

--
View this message in context: http://forum.openscad.org/Combining-polyhedrons-to-make-a-solid-tp10750p10753.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Ok, so I was afraid of that. The problem arises if you want to create a 3D object, made of many individual 2D polyhedron parts that is only solid when all the parts are combined. Creating one huge polyhedron would create a huge list of points and point references in the faces. Designing and troubleshooting that can be a nightmare. Editing it would be even worse since all the face references might need to be adjusted. To address this I created a function to combine multiple individual polyhedrons into one large polyhedron. This way all the point references in the individual polyhedron faces will only reference their own points. In case anyone else has the same issue here is my function. Below is the simple example from above created from two separate [point, faces] lists. Each polyhedron can be rendered separately while designing (try it by using polyhedron(points=poly1[0], faces=poly1[1]) but is combined to make the final solid. This does F6! //input is a list of [points, faces] //For each faces, increment the point references by the previous number of points function combine_polyhedrons(list, points=[], faces=[], point_count=0, i=0) = i < len(list) ? combine_polyhedrons(list, concat(points, list[i][0]), concat(faces, [for (face_i = [0:len(list[i][1])-1]) [for (point_i = [0:len(list[i][1][face_i])-1]) list[i][1][face_i][point_i] + point_count]]), point_count + len(list[i][0]), i + 1) : [points, faces]; //Each poly is [points, faces] poly1 = [[ [0,0,0],[10,0,0],[10,0,10],[0,0,10], [0,10,0],[0,10,10],[10,10,10],[10,10,0] ], [ [0,3,2,1,0], [0,4,5,3],[5,4,7,6,5],[1,2,6,7,1], [0,1,7,4,0] ] ]; poly2 = [[ [0,0,10],[0,10,10],[10,10,10],[10,0,10] ], [ [0,1,2,3,0] ] ]; new_polyhendron = combine_polyhedrons([poly1, poly2]); polyhedron(points=new_polyhendron[0], faces=new_polyhendron[1]); -- View this message in context: http://forum.openscad.org/Combining-polyhedrons-to-make-a-solid-tp10750p10753.html Sent from the OpenSCAD mailing list archive at Nabble.com.
MK
Marius Kintel
Sat, Dec 27, 2014 8:06 PM

On Dec 27, 2014, at 13:16 PM, NathanA napter@gmail.com wrote:

Is it possible to combine 2D objects to make a solid?

If your final polyhedron is convex, you can take the hull of the partial ones.

-Marius

On Dec 27, 2014, at 13:16 PM, NathanA <napter@gmail.com> wrote: > Is it possible to combine 2D objects to make a solid? If your final polyhedron is convex, you can take the hull of the partial ones. -Marius