understanding the

13 messages
Open this post in threaded view
|

understanding the

 Here's something I'm having trouble understanding, if someone can help me understand I'd be very appreciative. Here's a nifty way of drawing a cube with cut off corners. But, it fails on the mirror of the corner at [1,1,1]. module corner(wid) {      corner_points = [[0,0,0],[1,0,0],[0,1,0],[0,0,1]];      corner_faces =  [[0,3,1],[0,2,3],[0,1,2],[1,3,2]];      polyhedron(wid*corner_points, corner_faces); } module cornercube(wid, cornerwid) {      cube_vertices = [[0,0,0],[0,0,1],[0,1,0],[0,1,1],                       [1,0,0],[1,0,1],[1,1,0],[1,1,1]];      difference() {          cube(wid);          for (v = cube_vertices) {              #translate(wid*v) mirror(v) corner(cornerwid);          }      } } cornercube(20,5); This code fixes things by handling that corner as a special case. Can someone explain to me what's different about the one corner? And is there some transformation that will work on all eight corners? module cornercube2(wid,cornerwid) {      cube_vertices7 = [[0,0,0],[0,0,1],[0,1,0],[0,1,1],                        [1,0,0],[1,0,1],[1,1,0]];      cube_vertices1 = [[1,1,1]];      difference() {          cube(wid);          for (v = cube_vertices7) {              translate(wid*v) mirror(v) corner(cornerwid);          }          for (v = cube_vertices1) {              #translate(wid*v) rotate([180,90,0]) corner(cornerwid);          }      } } cornercube2(20,5); _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

Re: understanding the

 I don't have how to test this now. Have you tried to visualize just the mirrored awkward corner? Something like:translate(10*[1,1,1]) mirror ( [1,1,1]) corner(3);% cube(10); _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

Re: understanding the

 In reply to this post by marhar Something is wrong with your logic.Intuitively, I would expect that a rotation and translation is needed to position each corner.You are using a mirror and a translation.It's been a while since I studied matrix transformations, but it seems to me that a rotation can *sometimes* be implemented using a mirror, but not in the general case. So maybe you are getting lucky, and a mirror just happens to be sufficient to perform the rotation in 7 of the 8 cases?On 4 August 2018 at 02:39, Mark Harrison wrote:Here's something I'm having trouble understanding, if someone can help me understand I'd be very appreciative. Here's a nifty way of drawing a cube with cut off corners. But, it fails on the mirror of the corner at [1,1,1]. module corner(wid) {     corner_points = [[0,0,0],[1,0,0],[0,1,0],[0,0,1]];     corner_faces =  [[0,3,1],[0,2,3],[0,1,2],[1,3,2]];     polyhedron(wid*corner_points, corner_faces); } module cornercube(wid, cornerwid) {     cube_vertices = [[0,0,0],[0,0,1],[0,1,0],[0,1,1],                      [1,0,0],[1,0,1],[1,1,0],[1,1,1]];     difference() {         cube(wid);         for (v = cube_vertices) {             #translate(wid*v) mirror(v) corner(cornerwid);         }     } } cornercube(20,5); This code fixes things by handling that corner as a special case. Can someone explain to me what's different about the one corner? And is there some transformation that will work on all eight corners? module cornercube2(wid,cornerwid) {     cube_vertices7 = [[0,0,0],[0,0,1],[0,1,0],[0,1,1],                       [1,0,0],[1,0,1],[1,1,0]];     cube_vertices1 = [[1,1,1]];     difference() {         cube(wid);         for (v = cube_vertices7) {             translate(wid*v) mirror(v) corner(cornerwid);         }         for (v = cube_vertices1) {             #translate(wid*v) rotate([180,90,0]) corner(cornerwid);         }     } } cornercube2(20,5); _______________________________________________ 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
Open this post in threaded view
|

Re: understanding the

 Another way to cut corners off a cube is to intersect it with an octahedron. I think the logic for this would be easier.On 4 August 2018 at 10:36, doug moen wrote:Something is wrong with your logic.Intuitively, I would expect that a rotation and translation is needed to position each corner.You are using a mirror and a translation.It's been a while since I studied matrix transformations, but it seems to me that a rotation can *sometimes* be implemented using a mirror, but not in the general case. So maybe you are getting lucky, and a mirror just happens to be sufficient to perform the rotation in 7 of the 8 cases?On 4 August 2018 at 02:39, Mark Harrison wrote:Here's something I'm having trouble understanding, if someone can help me understand I'd be very appreciative. Here's a nifty way of drawing a cube with cut off corners. But, it fails on the mirror of the corner at [1,1,1]. module corner(wid) {     corner_points = [[0,0,0],[1,0,0],[0,1,0],[0,0,1]];     corner_faces =  [[0,3,1],[0,2,3],[0,1,2],[1,3,2]];     polyhedron(wid*corner_points, corner_faces); } module cornercube(wid, cornerwid) {     cube_vertices = [[0,0,0],[0,0,1],[0,1,0],[0,1,1],                      [1,0,0],[1,0,1],[1,1,0],[1,1,1]];     difference() {         cube(wid);         for (v = cube_vertices) {             #translate(wid*v) mirror(v) corner(cornerwid);         }     } } cornercube(20,5); This code fixes things by handling that corner as a special case. Can someone explain to me what's different about the one corner? And is there some transformation that will work on all eight corners? module cornercube2(wid,cornerwid) {     cube_vertices7 = [[0,0,0],[0,0,1],[0,1,0],[0,1,1],                       [1,0,0],[1,0,1],[1,1,0]];     cube_vertices1 = [[1,1,1]];     difference() {         cube(wid);         for (v = cube_vertices7) {             translate(wid*v) mirror(v) corner(cornerwid);         }         for (v = cube_vertices1) {             #translate(wid*v) rotate([180,90,0]) corner(cornerwid);         }     } } cornercube2(20,5); _______________________________________________ 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
Open this post in threaded view
|

Re: understanding the

Open this post in threaded view
|

Re: understanding the

 In reply to this post by doug.moen On 04. aug. 2018 16:38, doug moen wrote: > Another way to cut corners off a cube is to intersect it with an > octahedron. I think the logic for this would be easier. Indeed. The solution is trivial if you write a module defining an octahedron with vertices on the main axes, distanced "size" from origin, i.e. module octahedron(size); Then you can do module cornercube(wid,cornerwid) {     intersection()     {        octahedron(size=wid*sqrt(2)-cornerwid/2);        cube(size:wid,center=true);     } } Carsten Arnholm _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

Re: understanding the

 Yeah Carsten, a more convenient way to code this would be: cornercube(20,5); module octahedron(d = 10)   scale(d*sqrt(3))   {     cylinder(r1=1, r2=0, h=sqrt(3)*.5, \$fn=4);       scale([1,1,-1])cylinder(r1=1, r2=0, h=sqrt(3)*.5, \$fn=4);   } module cornercube(d=20, d1=5)   intersection()   {         cube(d, true);     octahedron(d-d1);   } -- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

Re: understanding the

 Sorry, I miscalculated the height of the octahedron. It is as easy as this: module octahedron(d = 10) {   scale(d*sqrt(3))   {     cylinder(r1=1, r2=0, h=1, \$fn=4);       scale([1,1,-1])cylinder(r1=1, r2=0, h=1, \$fn=4);   } } -- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

Re: understanding the

 On 2018-08-07 13:05, Parkinbot wrote: > Sorry, I miscalculated the height of the octahedron. It is as easy as > this: > > module octahedron(d = 10) > { >   scale(d*sqrt(3)) >   { >     cylinder(r1=1, r2=0, h=1, \$fn=4); >     scale([1,1,-1])cylinder(r1=1, r2=0, h=1, \$fn=4); >   } > } Yes, you can do it this way, although it is "cheating" as it relies on the OpenSCAD discretization of a cylinder instead of defining the polyhedron explicitly. It is more compact, but less readable. I used a different approach in my own code (not openSCAD), realising that any convex polyhedron can be defined from just an array of vertex coordinates. An octahedron is just one of many in this category https://gist.github.com/arnholm/c71852301b56b318a83a59c20bb29fe8Carsten Arnholm _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

Re: understanding the

 I don't think that using language primitives is "cheating", but I understand what you mean. The main problem with the code given by the threadstarter is that the cube is not centered. With a centered cube everything is clear and easy.   Btw, there was another calculation error in my octahedron. I hope this the final version: module octahedron(d = 10) {   x = d * 2 *sqrt(5)/3;   scale(x)   {     cylinder(r1=1, r2=0, h=1, \$fn=4);       scale([1,1,-1])cylinder(r1=1, r2=0, h=1, \$fn=4);   } }   -- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

Re: understanding the

 In reply to this post by cacb Em ter, 7 de ago de 2018 12:27, Carsten wrote: I used a different approach in my own code (not openSCAD), realising that any convex polyhedron can be defined from just an array of vertex coordinates. A similar approach in OpenSCAD language might be:module octahedron(r=1) {   verts = [ [r,0,0], [0,r,0], [-r,0,0],       [0, -r,0], [0,0,r], [0,0,-r] ] ;   hull( polyhedron(verts, [0,1,2,3,4,5]) );}  _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org