discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

A stack of polyhedrons - getting 2D shapes instead of 3D

A
amundsen
Wed, Jun 24, 2020 9:05 PM

Hello,

I am trying to build a stack of polyhedra with each polyhedron build between
two semi-random 4-edges polygons. Also, the ceiling of a polyhedron is the
floor of the next one.

However I get weird results, and after rendering I get 2D shapes only.

What's wrong?

l_4 = [rands(-1,0,1)[0], rands(-1,0,1)[0], 0];
l_3 = [rands(-1,0,1)[0], rands(1,0,1)[0], 0];
l_2 = [rands(1,0,1)[0], rands(1,0,1)[0], 0];
l_1 = [rands(1,0,1)[0], rands(-1,0,1)[0], 0];

union() {
for(i=[1:10]) {
u_1 = [rands(-1,0,1)[0], rands(-1,0,1)[0],i];
u_2 = [rands(-1,0,1)[0], rands(1,0,1)[0], i];
u_3 = [rands(1,0,1)[0], rands(1,0,1)[0], i];
u_4 = [rands(1,0,1)[0], rands(-1,0,1)[0], i];
my_points = [l_1, l_2, l_3, l_4, u_1, u_2, u_3, u_4];
my_faces = [[0,1,2,3], [0,1,5,4], [1,2,6,5], [2,3,7,6], [3,0,4,7],
[4,5,6,7]];
polyhedron(points = my_points, faces = my_faces, convexity = 10);
l_1 = [rands(-1,0,1)[0], rands(-1,0,1)[0], i-1];
l_2 = [rands(-1,0,1)[0], rands(1,0,1)[0], i-1];
l_3 = [rands(1,0,1)[0], rands(1,0,1)[0], i-1];
l_4 = [rands(1,0,1)[0], rands(-1,0,1)[0], i-1];
}
}

--
Sent from: http://forum.openscad.org/

Hello, I am trying to build a stack of polyhedra with each polyhedron build between two semi-random 4-edges polygons. Also, the ceiling of a polyhedron is the floor of the next one. However I get weird results, and after rendering I get 2D shapes only. What's wrong? l_4 = [rands(-1,0,1)[0], rands(-1,0,1)[0], 0]; l_3 = [rands(-1,0,1)[0], rands(1,0,1)[0], 0]; l_2 = [rands(1,0,1)[0], rands(1,0,1)[0], 0]; l_1 = [rands(1,0,1)[0], rands(-1,0,1)[0], 0]; union() { for(i=[1:10]) { u_1 = [rands(-1,0,1)[0], rands(-1,0,1)[0],i]; u_2 = [rands(-1,0,1)[0], rands(1,0,1)[0], i]; u_3 = [rands(1,0,1)[0], rands(1,0,1)[0], i]; u_4 = [rands(1,0,1)[0], rands(-1,0,1)[0], i]; my_points = [l_1, l_2, l_3, l_4, u_1, u_2, u_3, u_4]; my_faces = [[0,1,2,3], [0,1,5,4], [1,2,6,5], [2,3,7,6], [3,0,4,7], [4,5,6,7]]; polyhedron(points = my_points, faces = my_faces, convexity = 10); l_1 = [rands(-1,0,1)[0], rands(-1,0,1)[0], i-1]; l_2 = [rands(-1,0,1)[0], rands(1,0,1)[0], i-1]; l_3 = [rands(1,0,1)[0], rands(1,0,1)[0], i-1]; l_4 = [rands(1,0,1)[0], rands(-1,0,1)[0], i-1]; } } -- Sent from: http://forum.openscad.org/
NH
nop head
Wed, Jun 24, 2020 9:14 PM

Some of your faces are inside out.

[image: image.png]

On Wed, 24 Jun 2020 at 22:06, amundsen roald.baudoux@brutele.be wrote:

Hello,

I am trying to build a stack of polyhedra with each polyhedron build
between
two semi-random 4-edges polygons. Also, the ceiling of a polyhedron is the
floor of the next one.

However I get weird results, and after rendering I get 2D shapes only.

What's wrong?

l_4 = [rands(-1,0,1)[0], rands(-1,0,1)[0], 0];
l_3 = [rands(-1,0,1)[0], rands(1,0,1)[0], 0];
l_2 = [rands(1,0,1)[0], rands(1,0,1)[0], 0];
l_1 = [rands(1,0,1)[0], rands(-1,0,1)[0], 0];

union() {
for(i=[1:10]) {
u_1 = [rands(-1,0,1)[0], rands(-1,0,1)[0],i];
u_2 = [rands(-1,0,1)[0], rands(1,0,1)[0], i];
u_3 = [rands(1,0,1)[0], rands(1,0,1)[0], i];
u_4 = [rands(1,0,1)[0], rands(-1,0,1)[0], i];
my_points = [l_1, l_2, l_3, l_4, u_1, u_2, u_3, u_4];
my_faces = [[0,1,2,3], [0,1,5,4], [1,2,6,5], [2,3,7,6],
[3,0,4,7],
[4,5,6,7]];
polyhedron(points = my_points, faces = my_faces, convexity
= 10);
l_1 = [rands(-1,0,1)[0], rands(-1,0,1)[0], i-1];
l_2 = [rands(-1,0,1)[0], rands(1,0,1)[0], i-1];
l_3 = [rands(1,0,1)[0], rands(1,0,1)[0], i-1];
l_4 = [rands(1,0,1)[0], rands(-1,0,1)[0], i-1];
}
}

--
Sent from: http://forum.openscad.org/


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

Some of your faces are inside out. [image: image.png] On Wed, 24 Jun 2020 at 22:06, amundsen <roald.baudoux@brutele.be> wrote: > Hello, > > I am trying to build a stack of polyhedra with each polyhedron build > between > two semi-random 4-edges polygons. Also, the ceiling of a polyhedron is the > floor of the next one. > > However I get weird results, and after rendering I get 2D shapes only. > > What's wrong? > > l_4 = [rands(-1,0,1)[0], rands(-1,0,1)[0], 0]; > l_3 = [rands(-1,0,1)[0], rands(1,0,1)[0], 0]; > l_2 = [rands(1,0,1)[0], rands(1,0,1)[0], 0]; > l_1 = [rands(1,0,1)[0], rands(-1,0,1)[0], 0]; > > union() { > for(i=[1:10]) { > u_1 = [rands(-1,0,1)[0], rands(-1,0,1)[0],i]; > u_2 = [rands(-1,0,1)[0], rands(1,0,1)[0], i]; > u_3 = [rands(1,0,1)[0], rands(1,0,1)[0], i]; > u_4 = [rands(1,0,1)[0], rands(-1,0,1)[0], i]; > my_points = [l_1, l_2, l_3, l_4, u_1, u_2, u_3, u_4]; > my_faces = [[0,1,2,3], [0,1,5,4], [1,2,6,5], [2,3,7,6], > [3,0,4,7], > [4,5,6,7]]; > polyhedron(points = my_points, faces = my_faces, convexity > = 10); > l_1 = [rands(-1,0,1)[0], rands(-1,0,1)[0], i-1]; > l_2 = [rands(-1,0,1)[0], rands(1,0,1)[0], i-1]; > l_3 = [rands(1,0,1)[0], rands(1,0,1)[0], i-1]; > l_4 = [rands(1,0,1)[0], rands(-1,0,1)[0], i-1]; > } > } > > > > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
TP
Torsten Paul
Wed, Jun 24, 2020 10:19 PM

The easiest way for stacking things that have heights
defined in a list is via a recursive module. As noted
by nophead, the winding order is important, so the
point generation needs to make sure it's clear how
to enumerate in defined way.

// https://gist.github.com/thehans/c1721ba161249ad6830c50f1891af7d0
function cmul(c1,c2) = let(a=c1[0],b=c1[1],c=c2[0],d=c2[1]) [ac-bd, ad+bc];
function cpow(v, n) = n > 0 ? cpow(cmul(v, [0,1]), n - 1) : v;

// generate 4 points in 1st quadrant and rotate so we
// end up with one point in each quadrant in defined
// order
function points(z) = [ for (n = [0:3]) [ each cpow(rands(3, 10, 2), n), z ] ];

faces = [
[0, 1, 2, 3],
for (a = [0:3]) [ 4+a, (1+a)%4, a ],
for (a = [0:3]) [ 4+a, 4+(1+a)%4, (a+1)%4 ],
[7, 6, 5, 4]
];

module p(heights, bottom, h = 0, i = 0) {
if (i < len(heights)) {
height = h + heights[i];
top = points(height);
polyhedron([ each bottom, each top ], faces);
p(heights, top, height, i + 1);
}
}

p(rands(5, 20, 10), points(0));

ciao,
Torsten.

The easiest way for stacking things that have heights defined in a list is via a recursive module. As noted by nophead, the winding order is important, so the point generation needs to make sure it's clear how to enumerate in defined way. // https://gist.github.com/thehans/c1721ba161249ad6830c50f1891af7d0 function cmul(c1,c2) = let(a=c1[0],b=c1[1],c=c2[0],d=c2[1]) [a*c-b*d, a*d+b*c]; function cpow(v, n) = n > 0 ? cpow(cmul(v, [0,1]), n - 1) : v; // generate 4 points in 1st quadrant and rotate so we // end up with one point in each quadrant in defined // order function points(z) = [ for (n = [0:3]) [ each cpow(rands(3, 10, 2), n), z ] ]; faces = [ [0, 1, 2, 3], for (a = [0:3]) [ 4+a, (1+a)%4, a ], for (a = [0:3]) [ 4+a, 4+(1+a)%4, (a+1)%4 ], [7, 6, 5, 4] ]; module p(heights, bottom, h = 0, i = 0) { if (i < len(heights)) { height = h + heights[i]; top = points(height); polyhedron([ each bottom, each top ], faces); p(heights, top, height, i + 1); } } p(rands(5, 20, 10), points(0)); ciao, Torsten.