discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

understanding the

MH
Mark Harrison
Sat, Aug 4, 2018 6:39 AM

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(widv) mirror(v) corner(cornerwid);
}
for (v = cube_vertices1) {
#translate(wid
v) rotate([180,90,0]) corner(cornerwid);
}
}
}
cornercube2(20,5);

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);
RP
Ronaldo Persiano
Sat, Aug 4, 2018 2:01 PM

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);

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);
DM
doug moen
Sat, Aug 4, 2018 2:36 PM

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 marhar@gmail.com 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(widv) mirror(v) corner(cornerwid);
}
for (v = cube_vertices1) {
#translate(wid
v) rotate([180,90,0]) corner(cornerwid);
}
}
}
cornercube2(20,5);


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

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 <marhar@gmail.com> 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 > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
DM
doug moen
Sat, Aug 4, 2018 2:38 PM

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 doug@moens.org 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 marhar@gmail.com 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(widv) mirror(v) corner(cornerwid);
}
for (v = cube_vertices1) {
#translate(wid
v) rotate([180,90,0]) corner(cornerwid);
}
}
}
cornercube2(20,5);


OpenSCAD mailing list
Discuss@lists.openscad.org
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 <doug@moens.org> 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 <marhar@gmail.com> 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 >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> > >
R
runsun
Sun, Aug 5, 2018 2:51 AM

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/

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 );&nbsp;$ Tips ;&nbsp;$ Snippets -- Sent from: http://forum.openscad.org/
CA
Carsten Arnholm
Sun, Aug 5, 2018 12:59 PM

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

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
P
Parkinbot
Tue, Aug 7, 2018 10:51 AM

Yeah Carsten,

a more convenient way to code this would be:

cornercube(20,5);
module octahedron(d = 10)
scale(dsqrt(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/

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/
P
Parkinbot
Tue, Aug 7, 2018 11:05 AM

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/

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/
A
arnholm@arnholm.org
Tue, Aug 7, 2018 11:26 AM

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

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
P
Parkinbot
Tue, Aug 7, 2018 11:41 AM

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/

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/