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 |
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 |
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 <[hidden email]> wrote: Here's something I'm having trouble understanding, if someone can help me understand I'd be very appreciative. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
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 <[hidden email]> wrote:
_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
In reply to this post by marhar
It's indeed a special case. If you transfer the original corner (red color)
DIRECTLY to its position (i.e., w/o mirror()), and compare its relationship with the one that is mirrored (teal color), you can see from the graph how it is a special case : <http://forum.openscad.org/file/t602/180804_4_corner_mirroring_1.png> Instead of mirroring 7 times to all corners, mirroring application like this can be better achieved by mirroring the original one (C0) to [x,0,0] corner --- make it C1. Then, mirror BOTH C0-C1 to [0,y,0], generating 4 corners, than again onto [0,0,z] to generate 8 corners: module corners(wid=20, cornerwid=5) { module mirror_dir(d) { mps = [[1,0,0],[0,1,0],[0,0,1]]; children(); //<==== original copy translate( wid*mps[d]) mirror( mps[d] ) children(); //<==== mirrored copy } mirror_dir(2) mirror_dir(1) mirror_dir(0) corner(cornerwid); } <http://forum.openscad.org/file/t602/180804_4_corner_mirroring_2.png> This would be a very good general mirroring module for future 8-corner mirroring. ----- $ Runsun Pan, PhD $ libs: scadx , doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), editor of choice: CudaText ( OpenSCAD lexer ); $ Tips ; $ Snippets -- Sent from: http://forum.openscad.org/ _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
$ Runsun Pan, PhD
$ libs: scadx, doctest, faces(git), offline doc(git), runscad.py(2,git), editor of choice: CudaText ( OpenSCAD lexer); $ Tips; $ Snippets |
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 |
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 |
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 |
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/c71852301b56b318a83a59c20bb29fe8 Carsten Arnholm _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
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 |
In reply to this post by cacb
Em ter, 7 de ago de 2018 12:27, Carsten wrote:
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 |
In reply to this post by cacb
> 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 agree on the readability, but I wouldn't consider it cheating. It's a well defined behaviour, it's not just some random effect of how it currently works. -- Sent from: http://forum.openscad.org/ _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
On 2018-08-09 07:50, Troberg wrote:
>> 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 agree on the readability, but I wouldn't consider it cheating. It's a > well > defined behaviour, it's not just some random effect of how it currently > works. That is why is said "cheating" (with quotes). It relies on implementation details such as the discretization of a cylinder (or a cone rather) plus it also relies on implicit union of 2 such objects. Granted, this is well known current OpenSCAD behavior, but still. It is also a special case that works only for creating an octahedron. If you wanted a different kind of convex polyhedron you would be out of luck with this approach. But for sure it solved the original problem as presented. Carsten Arnholm _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
Free forum by Nabble | Edit this page |