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

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

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

amundsen
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
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

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

nophead
Some of your faces are inside out.

image.png

On Wed, 24 Jun 2020 at 22:06, amundsen <[hidden email]> 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
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
tp3
Reply | Threaded
Open this post in threaded view
|

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

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


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
-- Torsten