discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

How to get the 'opposite' of a rotation?

JB
Jordan Brown
Wed, Mar 22, 2023 5:12 PM

On 3/22/2023 9:05 AM, Sanjeev Prabhakar wrote:

module rot_ang(p=[])
{

rotate([0,0,p.z])
rotate([0,p.y,0])
rotate([p.x,0,0])children();

}

Isn't that exactly the same as rotate() itself?

On 3/22/2023 9:05 AM, Sanjeev Prabhakar wrote: > > module rot_ang(p=[]) > { > > rotate([0,0,p.z]) > rotate([0,p.y,0]) > rotate([p.x,0,0])children(); > > } Isn't that exactly the same as rotate() itself?
SP
Sanjeev Prabhakar
Wed, Mar 22, 2023 11:36 PM

You are right
rot_ang() does the same work as rotate()
Wrote just for readability

On Wed, 22 Mar, 2023, 10:42 pm Jordan Brown, openscad@jordan.maileater.net
wrote:

On 3/22/2023 9:05 AM, Sanjeev Prabhakar wrote:

module rot_ang(p=[])
{

rotate([0,0,p.z])
rotate([0,p.y,0])
rotate([p.x,0,0])children();

}

Isn't that exactly the same as rotate() itself?

You are right rot_ang() does the same work as rotate() Wrote just for readability On Wed, 22 Mar, 2023, 10:42 pm Jordan Brown, <openscad@jordan.maileater.net> wrote: > On 3/22/2023 9:05 AM, Sanjeev Prabhakar wrote: > > > module rot_ang(p=[]) > { > > rotate([0,0,p.z]) > rotate([0,p.y,0]) > rotate([p.x,0,0])children(); > > } > > > Isn't that exactly the same as rotate() itself? > >
BC
Bob Carlson
Thu, Mar 23, 2023 1:09 AM

Rotate using a vector requires needless brainpower. It’s more verbose but I always use xrot, yrot, and zrot from BOSL2. It’s much more readable. I use up/down, left/right, etc. for the same reason. WIth these, reversing an action is always pretty obvious.

-Bob
Tucson AZ

On Mar 21, 2023, at 14:04, Steve Lelievre steve.lelievre.canada@gmail.com wrote:

Hi everyone,

I have a small problem relating to how to use OpenSCAD to 'unrotate' things. I hope someone here can help me ...

Say I have an object that I have rotated to a new position. I want to get it back to where it started. However, rotating back with a negated version of the first rotation doesn't bring an object back to its original position. The following code sample shows the issue: the red cylinder does not end up superimposed over the green cylinder.

r1 = [30, 40, 50];
r2 = -r1;
color("green") cylinder(h=50);
rotate(r1) color("orange") cylinder(h=50);
rotate(r2) rotate(r1) color("red") cylinder(h=50);

I realize this is because of the way rotation matrices/vectors works but I don't know enough about the algebra to get to the solution for myself.  I also understand that I can break the reverse process down into three steps to get the desired result by using rotate([-r1.x,0,0]) rotate([0,-r1.y, 0]) rotate([0,0,-r1.z])  rotate(r1) color("red") cylinder(h=50);

Doing it with three steps is a cumbersome fix, so I want to generate the required r2 directly from r1.  How do I do that?

Thanks,

Steve


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Rotate using a vector requires needless brainpower. It’s more verbose but I always use xrot, yrot, and zrot from BOSL2. It’s much more readable. I use up/down, left/right, etc. for the same reason. WIth these, reversing an action is always pretty obvious. -Bob Tucson AZ On Mar 21, 2023, at 14:04, Steve Lelievre <steve.lelievre.canada@gmail.com> wrote: Hi everyone, I have a small problem relating to how to use OpenSCAD to 'unrotate' things. I hope someone here can help me ... Say I have an object that I have rotated to a new position. I want to get it back to where it started. However, rotating back with a negated version of the first rotation doesn't bring an object back to its original position. The following code sample shows the issue: the red cylinder does not end up superimposed over the green cylinder. r1 = [30, 40, 50]; r2 = -r1; color("green") cylinder(h=50); rotate(r1) color("orange") cylinder(h=50); rotate(r2) rotate(r1) color("red") cylinder(h=50); I realize this is because of the way rotation matrices/vectors works but I don't know enough about the algebra to get to the solution for myself. I also understand that I can break the reverse process down into three steps to get the desired result by using rotate([-r1.x,0,0]) rotate([0,-r1.y, 0]) rotate([0,0,-r1.z]) rotate(r1) color("red") cylinder(h=50); Doing it with three steps is a cumbersome fix, so I want to generate the required r2 directly from r1. How do I do that? Thanks, Steve _______________________________________________ OpenSCAD mailing list To unsubscribe send an email to discuss-leave@lists.openscad.org