discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

How to get the 'opposite' of a rotation?

FH
Father Horton
Wed, Mar 22, 2023 1:00 AM

There is no straightforward non-hairy way to do that without matrices, as
far as I can tell.

On Tue, Mar 21, 2023 at 6:36 PM Steve Lelievre <
steve.lelievre.canada@gmail.com> wrote:

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


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

There is no straightforward non-hairy way to do that without matrices, as far as I can tell. On Tue, Mar 21, 2023 at 6:36 PM Steve Lelievre < steve.lelievre.canada@gmail.com> wrote: > 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"); > > > > > > > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
FH
Father Horton
Wed, Mar 22, 2023 1:08 AM

It's not even easy with matrices because OpenSCAD doesn't have a matrix
invert function built-in. Whosawhastsis's suggestion is probably the best.

On Tue, Mar 21, 2023 at 8:00 PM Father Horton fatherhorton@gmail.com
wrote:

There is no straightforward non-hairy way to do that without matrices, as
far as I can tell.

On Tue, Mar 21, 2023 at 6:36 PM Steve Lelievre <
steve.lelievre.canada@gmail.com> wrote:

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


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

It's not even easy _with_ matrices because OpenSCAD doesn't have a matrix invert function built-in. Whosawhastsis's suggestion is probably the best. On Tue, Mar 21, 2023 at 8:00 PM Father Horton <fatherhorton@gmail.com> wrote: > There is no straightforward non-hairy way to do that without matrices, as > far as I can tell. > > On Tue, Mar 21, 2023 at 6:36 PM Steve Lelievre < > steve.lelievre.canada@gmail.com> wrote: > >> 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"); >> >> >> >> >> >> >> >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org >> >
JB
Jordan Brown
Wed, Mar 22, 2023 1:11 AM

On 3/21/2023 2:15 PM, Karl Exler wrote:

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

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.

Those "r" vectors are rotation vectors.  They don't have anything to do
with the cylinder radius.  He didn't specify the cylinder radius, so it
defaults to 1.

And if you're wondering what a rotation vector means... it's [rx, ry,
rz], giving the amount to rotate around the X axis, the Y axis, and the
Z axis, in that order.

On 3/21/2023 2:15 PM, Karl Exler wrote: >> 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); > 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. Those "r" vectors are rotation vectors.  They don't have anything to do with the cylinder radius.  He didn't specify the cylinder radius, so it defaults to 1. And if you're wondering what a rotation vector means... it's [rx, ry, rz], giving the amount to rotate around the X axis, the Y axis, and the Z axis, in that order.
AM
Adrian Mariano
Wed, Mar 22, 2023 2:02 AM

The right way to represent direction vectors is as direction vectors, that
is [x,y,z], not as a weird combination of cryptic angles.  That is the
customary way of doing it.

Note to Father Horton:  It's really not that hard to write a transpose
function, so OpenSCAD lacking matrix inverse isn't a big deal in this
case---because for rotation matrices, the inverse is just the transpose.

On Tue, Mar 21, 2023 at 7:36 PM Steve Lelievre <
steve.lelievre.canada@gmail.com> wrote:

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


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

The right way to represent direction vectors is as direction vectors, that is [x,y,z], not as a weird combination of cryptic angles. That is the customary way of doing it. Note to Father Horton: It's really not that hard to write a transpose function, so OpenSCAD lacking matrix inverse isn't a big deal in this case---because for rotation matrices, the inverse is just the transpose. On Tue, Mar 21, 2023 at 7:36 PM Steve Lelievre < steve.lelievre.canada@gmail.com> wrote: > 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"); > > > > > > > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
RD
Revar Desmera
Wed, Mar 22, 2023 2:03 AM

Using BOSL2, there are a couple ways you can do the opposite rotation.  If you use matrices, you can do it thus:

include <BOSL2/std.scad>
r1 = rot([30, 40, 50]);
r2 = matrix_inverse(r1);
color("green") cylinder(h=50);
rotate(r1) color("orange") cylinder(h=50);
rotate(r2) rotate(r1) color("red") cylinder(h=50);

More simply, however, is to use the rot(..., reverse=true) module:

include <BOSL2/std.scad>
r1 = [30, 40, 50];
color("green") cylinder(h=50);
rot(r1) color("orange") cylinder(h=50);
rot(r1, reverse=true) rot(r1) color("red") cylinder(h=50);

-Revar

Using BOSL2, there are a couple ways you can do the opposite rotation. If you use matrices, you can do it thus: include <BOSL2/std.scad> r1 = rot([30, 40, 50]); r2 = matrix_inverse(r1); color("green") cylinder(h=50); rotate(r1) color("orange") cylinder(h=50); rotate(r2) rotate(r1) color("red") cylinder(h=50); More simply, however, is to use the `rot(..., reverse=true)` module: include <BOSL2/std.scad> r1 = [30, 40, 50]; color("green") cylinder(h=50); rot(r1) color("orange") cylinder(h=50); rot(r1, reverse=true) rot(r1) color("red") cylinder(h=50); -Revar
RD
Revar Desmera
Wed, Mar 22, 2023 2:06 AM

I err.  The rotate()s in the first example should be multmatrix().

  • Revar

On Mar 21, 2023, at 7:03 PM, Revar Desmera revarbat@gmail.com wrote:

Using BOSL2, there are a couple ways you can do the opposite rotation.  If you use matrices, you can do it thus:

include <BOSL2/std.scad>
r1 = rot([30, 40, 50]);
r2 = matrix_inverse(r1);
color("green") cylinder(h=50);
rotate(r1) color("orange") cylinder(h=50);
rotate(r2) rotate(r1) color("red") cylinder(h=50);

More simply, however, is to use the rot(..., reverse=true) module:

include <BOSL2/std.scad>
r1 = [30, 40, 50];
color("green") cylinder(h=50);
rot(r1) color("orange") cylinder(h=50);
rot(r1, reverse=true) rot(r1) color("red") cylinder(h=50);

-Revar

I err. The `rotate()`s in the first example should be `multmatrix()`. - Revar > On Mar 21, 2023, at 7:03 PM, Revar Desmera <revarbat@gmail.com> wrote: > > Using BOSL2, there are a couple ways you can do the opposite rotation. If you use matrices, you can do it thus: > > include <BOSL2/std.scad> > r1 = rot([30, 40, 50]); > r2 = matrix_inverse(r1); > color("green") cylinder(h=50); > rotate(r1) color("orange") cylinder(h=50); > rotate(r2) rotate(r1) color("red") cylinder(h=50); > > More simply, however, is to use the `rot(..., reverse=true)` module: > > include <BOSL2/std.scad> > r1 = [30, 40, 50]; > color("green") cylinder(h=50); > rot(r1) color("orange") cylinder(h=50); > rot(r1, reverse=true) rot(r1) color("red") cylinder(h=50); > > -Revar
FH
Father Horton
Wed, Mar 22, 2023 2:10 AM

And so I have learned something today. Thank you.

On Tue, Mar 21, 2023 at 9:02 PM Adrian Mariano avm4@cornell.edu wrote:

The right way to represent direction vectors is as direction vectors, that
is [x,y,z], not as a weird combination of cryptic angles.  That is the
customary way of doing it.

Note to Father Horton:  It's really not that hard to write a transpose
function, so OpenSCAD lacking matrix inverse isn't a big deal in this
case---because for rotation matrices, the inverse is just the transpose.

On Tue, Mar 21, 2023 at 7:36 PM Steve Lelievre <
steve.lelievre.canada@gmail.com> wrote:

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


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

And so I have learned something today. Thank you. On Tue, Mar 21, 2023 at 9:02 PM Adrian Mariano <avm4@cornell.edu> wrote: > The right way to represent direction vectors is as direction vectors, that > is [x,y,z], not as a weird combination of cryptic angles. That is the > customary way of doing it. > > Note to Father Horton: It's really not that hard to write a transpose > function, so OpenSCAD lacking matrix inverse isn't a big deal in this > case---because for rotation matrices, the inverse is just the transpose. > > > > On Tue, Mar 21, 2023 at 7:36 PM Steve Lelievre < > steve.lelievre.canada@gmail.com> wrote: > >> 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"); >> >> >> >> >> >> >> >> _______________________________________________ >> 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 >
SP
Sanjeev Prabhakar
Wed, Mar 22, 2023 2:16 AM

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

On Wed, 22 Mar 2023 at 02:35, 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

try this r1 = [30, 40, 50]; r2 = -r1/360; color("green") cylinder(h=50); rotate(r1) color("orange") cylinder(h=50); rotate(r2) rotate(r1) color("red") cylinder(h=50); On Wed, 22 Mar 2023 at 02:35, 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 >
LM
Leonard Martin Struttmann
Wed, Mar 22, 2023 2:18 AM

Would using quaternions make this easier?

On Tue, Mar 21, 2023 at 9:17 PM Sanjeev Prabhakar sprabhakar2006@gmail.com
wrote:

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

On Wed, 22 Mar 2023 at 02:35, 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

Would using quaternions make this easier? On Tue, Mar 21, 2023 at 9:17 PM Sanjeev Prabhakar <sprabhakar2006@gmail.com> wrote: > try this > r1 = [30, 40, 50]; > r2 = -r1/360; > color("green") cylinder(h=50); > rotate(r1) color("orange") cylinder(h=50); > rotate(r2) rotate(r1) color("red") cylinder(h=50); > > On Wed, 22 Mar 2023 at 02:35, 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 >
AM
Adrian Mariano
Wed, Mar 22, 2023 2:24 AM

While using the matrix_inverse() function in BOSL2 will work, you should
really instead use rot_inverse() which will invert rotations around any
center point using the appropriate translation and matrix transpose.  This
will be faster and more accurate than invoking matrix_inverse().

On Tue, Mar 21, 2023 at 10:04 PM Revar Desmera revarbat@gmail.com wrote:

Using BOSL2, there are a couple ways you can do the opposite rotation.  If
you use matrices, you can do it thus:

include <BOSL2/std.scad>
r1 = rot([30, 40, 50]);
r2 = matrix_inverse(r1);
color("green") cylinder(h=50);
rotate(r1) color("orange") cylinder(h=50);
rotate(r2) rotate(r1) color("red") cylinder(h=50);

More simply, however, is to use the rot(..., reverse=true) module:

include <BOSL2/std.scad>
r1 = [30, 40, 50];
color("green") cylinder(h=50);
rot(r1) color("orange") cylinder(h=50);
rot(r1, reverse=true) rot(r1) color("red") cylinder(h=50);

-Revar


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

While using the matrix_inverse() function in BOSL2 will work, you should really instead use rot_inverse() which will invert rotations around any center point using the appropriate translation and matrix transpose. This will be faster and more accurate than invoking matrix_inverse(). On Tue, Mar 21, 2023 at 10:04 PM Revar Desmera <revarbat@gmail.com> wrote: > Using BOSL2, there are a couple ways you can do the opposite rotation. If > you use matrices, you can do it thus: > > include <BOSL2/std.scad> > r1 = rot([30, 40, 50]); > r2 = matrix_inverse(r1); > color("green") cylinder(h=50); > rotate(r1) color("orange") cylinder(h=50); > rotate(r2) rotate(r1) color("red") cylinder(h=50); > > > More simply, however, is to use the `rot(..., reverse=true)` module: > > include <BOSL2/std.scad> > r1 = [30, 40, 50]; > color("green") cylinder(h=50); > rot(r1) color("orange") cylinder(h=50); > rot(r1, reverse=true) rot(r1) color("red") cylinder(h=50); > > -Revar > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >