discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

How to get the 'opposite' of a rotation?

SL
Steve Lelievre
Tue, Mar 21, 2023 9:04 PM

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

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
KE
Karl Exler
Tue, Mar 21, 2023 9:15 PM

I can't help but I am a newie in Openscad.. but your question leads me
to a new question.

What is the sense from the vector in r1 ??

Due to my understanding a cylinder can only have one radius... if it has
two it is a cone.

sorry,
Karl

Am 21.03.23 um 22:04 schrieb Steve Lelievre:

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

I can't help but I am a newie in Openscad.. but your question leads me to a new question. What is the sense from the vector in r1 ?? Due to my understanding a cylinder can only have one radius... if it has two it is a cone. sorry, Karl Am 21.03.23 um 22:04 schrieb Steve Lelievre: > 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
NH
nop head
Tue, Mar 21, 2023 9:24 PM

I can do it with NopSCADlib as follows;

include <NopSCADlib/lib.scad>

r1 = [30, 40, 50];
r2 = vec3(invert(rotate(r1)) * [1, 0, 0, 0]);
//r2 = -r1;
color("green") cylinder(h=50);
rotate(r1) color("orange") cylinder(h=50);
rotate(r2) rotate(r1) color("red") cylinder(h=50);

I.e. I convert the rotation vector to a matrix and then invert it and
multiply by a unit vector in the x direction. If the matrix is only
rotations you can replace the matrix inversion with transpose(), I.e. swap
the rows and columns.

On Tue, 21 Mar 2023 at 21: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

I can do it with NopSCADlib as follows; include <NopSCADlib/lib.scad> r1 = [30, 40, 50]; r2 = vec3(invert(rotate(r1)) * [1, 0, 0, 0]); //r2 = -r1; color("green") cylinder(h=50); rotate(r1) color("orange") cylinder(h=50); rotate(r2) rotate(r1) color("red") cylinder(h=50); I.e. I convert the rotation vector to a matrix and then invert it and multiply by a unit vector in the x direction. If the matrix is only rotations you can replace the matrix inversion with transpose(), I.e. swap the rows and columns. On Tue, 21 Mar 2023 at 21: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 >
AM
Adrian Mariano
Tue, Mar 21, 2023 9:38 PM

Similar methods work in BOSL2, of course.  The question I ask is why the
interest specifically in inverting a rotation of that form?  I personally
find the Euler angle rotations very un-intuitive and never rotate by more
than one axis at a time.  Then inverting is easy.  You can do this easily
in BOSL2 by multiplying the matrices of all the rotations together to get
one rotation matrix if you like.  You can then apply it (and its transpose,
the inverse) using multmatrix().

The only other intuitive representation for rotations is to pick an
arbitrary axis and rotate around that, and in that case, the inverse
rotation is again immediately obvious.

On Tue, Mar 21, 2023 at 5:26 PM nop head nop.head@gmail.com wrote:

I can do it with NopSCADlib as follows;

include <NopSCADlib/lib.scad>

r1 = [30, 40, 50];
r2 = vec3(invert(rotate(r1)) * [1, 0, 0, 0]);
//r2 = -r1;
color("green") cylinder(h=50);
rotate(r1) color("orange") cylinder(h=50);
rotate(r2) rotate(r1) color("red") cylinder(h=50);

I.e. I convert the rotation vector to a matrix and then invert it and
multiply by a unit vector in the x direction. If the matrix is only
rotations you can replace the matrix inversion with transpose(), I.e. swap
the rows and columns.

On Tue, 21 Mar 2023 at 21: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


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

Similar methods work in BOSL2, of course. The question I ask is why the interest specifically in inverting a rotation of that form? I personally find the Euler angle rotations very un-intuitive and never rotate by more than one axis at a time. Then inverting is easy. You can do this easily in BOSL2 by multiplying the matrices of all the rotations together to get one rotation matrix if you like. You can then apply it (and its transpose, the inverse) using multmatrix(). The only other intuitive representation for rotations is to pick an arbitrary axis and rotate around that, and in that case, the inverse rotation is again immediately obvious. On Tue, Mar 21, 2023 at 5:26 PM nop head <nop.head@gmail.com> wrote: > I can do it with NopSCADlib as follows; > > include <NopSCADlib/lib.scad> > > r1 = [30, 40, 50]; > r2 = vec3(invert(rotate(r1)) * [1, 0, 0, 0]); > //r2 = -r1; > color("green") cylinder(h=50); > rotate(r1) color("orange") cylinder(h=50); > rotate(r2) rotate(r1) color("red") cylinder(h=50); > > I.e. I convert the rotation vector to a matrix and then invert it and > multiply by a unit vector in the x direction. If the matrix is only > rotations you can replace the matrix inversion with transpose(), I.e. swap > the rows and columns. > > > > On Tue, 21 Mar 2023 at 21: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 >> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
NH
nop head
Tue, Mar 21, 2023 9:38 PM

Actually that was incorrect.
Should have been r2 = vec3(invert(rotate(r1)) * [0, 0, 0, 1]);

Actually that was incorrect. Should have been r2 = vec3(invert(rotate(r1)) * [0, 0, 0, 1]);
CM
Curt McDowell
Tue, Mar 21, 2023 9:43 PM

You could write a separate module to undo the rotation. The example
below breaks the process into three steps as you suggested, but those
steps are abstracted out once by an easy-to-understand module. Most
importantly, the points where you call the module look as simple an
intuitive as can be.

module undo_rotate(v)
    rotate([-v.x, 0, 0])
        rotate([0, -v.y, 0])
            rotate([0, 0, -v.z])
                children();

undo_rotate([30, 40, 50])
    rotate([30, 40, 50])
        cube([10, 20, 30]);

Personally, I avoid using the multiple-angle form of rotate() because it
obscures the type and order of rotations being performed. The
broken-down version is not so cumbersome really, and is clearer.

Regards,
Curt

On 3/21/2023 2:04 PM, Steve Lelievre wrote:

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?

You could write a separate module to undo the rotation. The example below breaks the process into three steps as you suggested, but those steps are abstracted out once by an easy-to-understand module. Most importantly, the points where you call the module look as simple an intuitive as can be. module undo_rotate(v)     rotate([-v.x, 0, 0])         rotate([0, -v.y, 0])             rotate([0, 0, -v.z])                 children(); undo_rotate([30, 40, 50])     rotate([30, 40, 50])         cube([10, 20, 30]); Personally, I avoid using the multiple-angle form of rotate() because it obscures the type and order of rotations being performed. The broken-down version is not so cumbersome really, and is clearer. Regards, Curt On 3/21/2023 2:04 PM, Steve Lelievre wrote: > 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?
FH
Father Horton
Tue, Mar 21, 2023 9:44 PM

https://en.wikipedia.org/wiki/Rotation_matrix

See the section on rotations in three dimensions.

On Tue, Mar 21, 2023 at 4:04 PM 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

https://en.wikipedia.org/wiki/Rotation_matrix See the section on rotations in three dimensions. On Tue, Mar 21, 2023 at 4:04 PM 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 >
NH
nop head
Tue, Mar 21, 2023 9:44 PM

Still wrong, too much wine.

Try this

r1 = [30, 40, 50];

r2 = euler(invert(rotate(r1)));

color("green") cylinder(h=50);
rotate(r1) color("orange") cylinder(h=50);
rotate(r2) rotate(r1) color("red") cylinder(h=49);

euler() converts a rotation matrix back to a vector.

[image: image.png]

On Tue, 21 Mar 2023 at 21:38, nop head nop.head@gmail.com wrote:

Actually that was incorrect.
Should have been r2 = vec3(invert(rotate(r1)) * [0, 0, 0, 1]);

Still wrong, too much wine. Try this r1 = [30, 40, 50]; r2 = euler(invert(rotate(r1))); color("green") cylinder(h=50); rotate(r1) color("orange") cylinder(h=50); rotate(r2) rotate(r1) color("red") cylinder(h=49); euler() converts a rotation matrix back to a vector. [image: image.png] On Tue, 21 Mar 2023 at 21:38, nop head <nop.head@gmail.com> wrote: > Actually that was incorrect. > Should have been r2 = vec3(invert(rotate(r1)) * [0, 0, 0, 1]); > > > >
W
Whosawhatsis
Tue, Mar 21, 2023 11:05 PM

Why not just make it a module?

module unrotate(angle) rotate([-angle[0], 0, 0]) rotate([0, -angle[1], 0]) rotate([0, 0, -angle[2]]) children();
On Mar 21, 2023 at 14:04 -0700, 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

Why not just make it a module? module unrotate(angle) rotate([-angle[0], 0, 0]) rotate([0, -angle[1], 0]) rotate([0, 0, -angle[2]]) children(); On Mar 21, 2023 at 14:04 -0700, 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
SL
Steve Lelievre
Tue, Mar 21, 2023 11:35 PM

Thanks, everyone, for your answers.

On 2023-03-21 2:38 p.m., Adrian Mariano wrote:

The question I ask is why the interest specifically in inverting a
rotation of that form?

It seemed like a handy way to define a direction for a vector arrow so
that's how I started off. Overall, my project is to use OpenSCAD to
create a diagram in the viewport with arrows for the axes, an arrow
towards toward the sun, and various other elements that I'll add later.

I have labels as part of the arrow objects and I want those labels to
appear face on to the viewport irrespective of the viewport rotation.
Therefore as I construct the objects I rotate the labels using $vpr then
un-rotate them according to my arrow rotation, then I apply that
rotation to the whole object.

Using Curt's module, I got I've got my code going (see code below with a
copy of the viewport image). I just have to redo the preview each time I
change the viewport rotation. I plan to animate the output, eventually.

If anyone is willing to spell it out for me, I'd still like to know how
to get r2 from r1, as in my original question? My math isn't up to
understanding the Wikipedia explanation of rotation matrices, nor in
particular, how to turn a 3x3 rotation matrix into the corresponding
vector variable that I would give to OpenSCAD's rotate.

Steve

$fn= 30;

module undo_rotate(v) rotate([-v.x, 0, 0]) rotate([0, -v.y, 0])
rotate([0, 0, -v.z]) children();

module arrow(rotation, length, label) {
   rotate(rotation) union() {
      cylinder(h=length, d = 0.75);
      translate([0, 0, length]) cylinder(r1 = 1, r2 = 0, h = 3);
      translate([0, 0, length + 7]) undo_rotate(rotation) rotate($vpr)
linear_extrude(1, center=true) text(label, valign="center",
halign="center", size=3);
   }
}

color("silver", 0.1) union() {
    arrow([0, 90, 0], 30, "E");
    arrow([-90, 0, 0], 30, "N");
    arrow([0, 0, 0], 30, "Z");
}

color("red") arrow([25,-45, 65], 30, "S");

Thanks, everyone, for your answers. On 2023-03-21 2:38 p.m., Adrian Mariano wrote: > The question I ask is why the interest specifically in inverting a > rotation of that form? It seemed like a handy way to define a direction for a vector arrow so that's how I started off. Overall, my project is to use OpenSCAD to create a diagram in the viewport with arrows for the axes, an arrow towards toward the sun, and various other elements that I'll add later. I have labels as part of the arrow objects and I want those labels to appear face on to the viewport irrespective of the viewport rotation. Therefore as I construct the objects I rotate the labels using $vpr then un-rotate them according to my arrow rotation, then I apply that rotation to the whole object. Using Curt's module, I got I've got my code going (see code below with a copy of the viewport image). I just have to redo the preview each time I change the viewport rotation. I plan to animate the output, eventually. If anyone is willing to spell it out for me, I'd still like to know how to get r2 from r1, as in my original question? My math isn't up to understanding the Wikipedia explanation of rotation matrices, nor in particular, how to turn a 3x3 rotation matrix into the corresponding vector variable that I would give to OpenSCAD's rotate. Steve > $fn= 30; > > module undo_rotate(v) rotate([-v.x, 0, 0]) rotate([0, -v.y, 0]) > rotate([0, 0, -v.z]) children(); > > module arrow(rotation, length, label) { >    rotate(rotation) union() { >       cylinder(h=length, d = 0.75); >       translate([0, 0, length]) cylinder(r1 = 1, r2 = 0, h = 3); >       translate([0, 0, length + 7]) undo_rotate(rotation) rotate($vpr) > linear_extrude(1, center=true) text(label, valign="center", > halign="center", size=3); >    } > } > > color("silver", 0.1) union() { >     arrow([0, 90, 0], 30, "E"); >     arrow([-90, 0, 0], 30, "N"); >     arrow([0, 0, 0], 30, "Z"); > } > > color("red") arrow([25,-45, 65], 30, "S");