discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

How to get the 'opposite' of a rotation?

SP
Sanjeev Prabhakar
Wed, Mar 22, 2023 2:38 AM

For using quaternion, I think you need to make your models through points
list.

In Openscad, i think there is no way but to rotate the objects step wise,
this can be done with a module as suggested by many here.

On Wed, 22 Mar 2023 at 07:49, Leonard Martin Struttmann <
lenstruttmann@gmail.com> wrote:

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


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

For using quaternion, I think you need to make your models through points list. In Openscad, i think there is no way but to rotate the objects step wise, this can be done with a module as suggested by many here. On Wed, 22 Mar 2023 at 07:49, Leonard Martin Struttmann < lenstruttmann@gmail.com> wrote: > 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 >> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
AM
Adrian Mariano
Wed, Mar 22, 2023 2:41 AM

Depends on what "this" means.  Matrices are super fast in OpenSCAD.  I
mean, any task you can do in OpenSCAD:  if you can do it with matrices that
will be the fastest way to do it.  Revar implemented quaternions.  They are
much slower.  Are quaternions somehow magically easier?  I don't think so.
Regardless of which representation you choose, you still have to write the
code to do things like the inverse operation.  And for quaternions you also
have to write code to do everything else as well.  And on top of that,
when you're done, you need to convert the quaternion into a matrix to hand
to multmatrix().  The truth is, doing matrices is not hard, and it's the
native approach for OpenSCAD.  And once someone has implemented the
necessary support for this, like can be found in nophead's library or
BOSL2, you don't need to look under the hood if you don't want to.

On Tue, Mar 21, 2023 at 10:19 PM Leonard Martin Struttmann <
lenstruttmann@gmail.com> wrote:

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


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

Depends on what "this" means. Matrices are super fast in OpenSCAD. I mean, any task you can do in OpenSCAD: if you can do it with matrices that will be the fastest way to do it. Revar implemented quaternions. They are much slower. Are quaternions somehow magically easier? I don't think so. Regardless of which representation you choose, you still have to write the code to do things like the inverse operation. And for quaternions you also have to write code to do everything else as well. And on top of that, when you're done, you need to convert the quaternion into a matrix to hand to multmatrix(). The truth is, doing matrices is not hard, and it's the native approach for OpenSCAD. And once someone has implemented the necessary support for this, like can be found in nophead's library or BOSL2, you don't need to look under the hood if you don't want to. On Tue, Mar 21, 2023 at 10:19 PM Leonard Martin Struttmann < lenstruttmann@gmail.com> wrote: > 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 >> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
SP
Sanjeev Prabhakar
Wed, Mar 22, 2023 2:50 AM

for a relatively new user with not much background in maths, it would be
tough.
Matrices are definitely faster though, but it would be even faster if you
have a formula to get a result in terms of simple multiplication and
division.

On Wed, 22 Mar 2023 at 08:12, Adrian Mariano avm4@cornell.edu wrote:

Depends on what "this" means.  Matrices are super fast in OpenSCAD.  I
mean, any task you can do in OpenSCAD:  if you can do it with matrices that
will be the fastest way to do it.  Revar implemented quaternions.  They are
much slower.  Are quaternions somehow magically easier?  I don't think so.
Regardless of which representation you choose, you still have to write the
code to do things like the inverse operation.  And for quaternions you also
have to write code to do everything else as well.  And on top of that,
when you're done, you need to convert the quaternion into a matrix to hand
to multmatrix().  The truth is, doing matrices is not hard, and it's the
native approach for OpenSCAD.  And once someone has implemented the
necessary support for this, like can be found in nophead's library or
BOSL2, you don't need to look under the hood if you don't want to.

On Tue, Mar 21, 2023 at 10:19 PM Leonard Martin Struttmann <
lenstruttmann@gmail.com> wrote:

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


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

for a relatively new user with not much background in maths, it would be tough. Matrices are definitely faster though, but it would be even faster if you have a formula to get a result in terms of simple multiplication and division. On Wed, 22 Mar 2023 at 08:12, Adrian Mariano <avm4@cornell.edu> wrote: > Depends on what "this" means. Matrices are super fast in OpenSCAD. I > mean, any task you can do in OpenSCAD: if you can do it with matrices that > will be the fastest way to do it. Revar implemented quaternions. They are > much slower. Are quaternions somehow magically easier? I don't think so. > Regardless of which representation you choose, you still have to write the > code to do things like the inverse operation. And for quaternions you also > have to write code to do everything else as well. And on top of that, > when you're done, you need to convert the quaternion into a matrix to hand > to multmatrix(). The truth is, doing matrices is not hard, and it's the > native approach for OpenSCAD. And once someone has implemented the > necessary support for this, like can be found in nophead's library or > BOSL2, you don't need to look under the hood if you don't want to. > > > > On Tue, Mar 21, 2023 at 10:19 PM Leonard Martin Struttmann < > lenstruttmann@gmail.com> wrote: > >> 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 >>> >> _______________________________________________ >> 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 3:18 AM

Not sure what you mean, Sanjeev.  Unless the problem is very constrained,
you cannot express rotations in terms of simple multiplications and
divisions.  Unless you mean that you unwrap all the matrix operations and
write them out without matrices, which is a mess.  A user without much
math background can benefit from a library that does the math "Under the
hood" for them.

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

for a relatively new user with not much background in maths, it would be
tough.
Matrices are definitely faster though, but it would be even faster if you
have a formula to get a result in terms of simple multiplication and
division.

On Wed, 22 Mar 2023 at 08:12, Adrian Mariano avm4@cornell.edu wrote:

Depends on what "this" means.  Matrices are super fast in OpenSCAD.  I
mean, any task you can do in OpenSCAD:  if you can do it with matrices that
will be the fastest way to do it.  Revar implemented quaternions.  They are
much slower.  Are quaternions somehow magically easier?  I don't think so.
Regardless of which representation you choose, you still have to write the
code to do things like the inverse operation.  And for quaternions you also
have to write code to do everything else as well.  And on top of that,
when you're done, you need to convert the quaternion into a matrix to hand
to multmatrix().  The truth is, doing matrices is not hard, and it's the
native approach for OpenSCAD.  And once someone has implemented the
necessary support for this, like can be found in nophead's library or
BOSL2, you don't need to look under the hood if you don't want to.

On Tue, Mar 21, 2023 at 10:19 PM Leonard Martin Struttmann <
lenstruttmann@gmail.com> wrote:

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


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


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

Not sure what you mean, Sanjeev. Unless the problem is very constrained, you cannot express rotations in terms of simple multiplications and divisions. Unless you mean that you unwrap all the matrix operations and write them out without matrices, which is a mess. A user without much math background can benefit from a library that does the math "Under the hood" for them. On Tue, Mar 21, 2023 at 10:51 PM Sanjeev Prabhakar <sprabhakar2006@gmail.com> wrote: > for a relatively new user with not much background in maths, it would be > tough. > Matrices are definitely faster though, but it would be even faster if you > have a formula to get a result in terms of simple multiplication and > division. > > On Wed, 22 Mar 2023 at 08:12, Adrian Mariano <avm4@cornell.edu> wrote: > >> Depends on what "this" means. Matrices are super fast in OpenSCAD. I >> mean, any task you can do in OpenSCAD: if you can do it with matrices that >> will be the fastest way to do it. Revar implemented quaternions. They are >> much slower. Are quaternions somehow magically easier? I don't think so. >> Regardless of which representation you choose, you still have to write the >> code to do things like the inverse operation. And for quaternions you also >> have to write code to do everything else as well. And on top of that, >> when you're done, you need to convert the quaternion into a matrix to hand >> to multmatrix(). The truth is, doing matrices is not hard, and it's the >> native approach for OpenSCAD. And once someone has implemented the >> necessary support for this, like can be found in nophead's library or >> BOSL2, you don't need to look under the hood if you don't want to. >> >> >> >> On Tue, Mar 21, 2023 at 10:19 PM Leonard Martin Struttmann < >> lenstruttmann@gmail.com> wrote: >> >>> 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 >>>> >>> _______________________________________________ >>> 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 >> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
SL
Steve Lelievre
Wed, Mar 22, 2023 3:19 AM

On 2023-03-21 7:02 p.m., Adrian Mariano 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.

Sure, but in my defense... I'm not actually doing vector math. I'm just
making an arrow that points off somewhere fairly random so that I can
use it to represent of a direction vector in a diagram drawn in the
viewport.

And actually, if I was worried about being exact, I would be starting
from angles anyway. This is for a celestial mechanics project and my
information about the Sun's position is its azimuth and altitude angles.
The angle form of rotate is a breeze for that:

rotate([-altitude, 0, -azimuth]) arrow();       // negation due to sign
conventions of solar angles; arrow initially on south meridian

Steve

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 todiscuss-leave@lists.openscad.org

On 2023-03-21 7:02 p.m., Adrian Mariano 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. Sure, but in my defense... I'm not actually doing vector math. I'm just making an arrow that points off somewhere fairly random so that I can use it to represent of a direction vector in a diagram drawn in the viewport. And actually, if I was worried about being exact, I would be starting from angles anyway. This is for a celestial mechanics project and my information about the Sun's position is its azimuth and altitude angles. The angle form of rotate is a breeze for that: rotate([-altitude, 0, -azimuth]) arrow();       // negation due to sign conventions of solar angles; arrow initially on south meridian Steve > > 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 todiscuss-leave@lists.openscad.org
KE
Karl Exler
Wed, Mar 22, 2023 5:52 AM

Thank you

Am 22.03.23 um 02:11 schrieb Jordan Brown:

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.

Thank you Am 22.03.23 um 02:11 schrieb Jordan Brown: > 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. >
SP
Sanjeev Prabhakar
Wed, Mar 22, 2023 4:05 PM

I have written an openscad simple module for your application.

i hope this helps

a=30;
b=40;
c=50;
r1 = [a, b, c];

module rot_ang(p=[])
{

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

}

module rot_angx(p=[])
{

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

}
color("green") cylinder(h=50);
rotate(r1) color("orange") cylinder(h=50);

rot_angx(r1)rot_ang(r1)color("red")cylinder(h=50);

On Wed, 22 Mar 2023 at 08:50, Steve Lelievre <
steve.lelievre.canada@gmail.com> wrote:

On 2023-03-21 7:02 p.m., Adrian Mariano 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.

Sure, but in my defense... I'm not actually doing vector math. I'm just
making an arrow that points off somewhere fairly random so that I can use
it to represent of a direction vector in a diagram drawn in the viewport.

And actually, if I was worried about being exact, I would be starting from
angles anyway. This is for a celestial mechanics project and my information
about the Sun's position is its azimuth and altitude angles. The angle form
of rotate is a breeze for that:

rotate([-altitude, 0, -azimuth]) arrow();      // negation due to sign
conventions of solar angles; arrow initially on south meridian

Steve

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


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

I have written an openscad simple module for your application. i hope this helps a=30; b=40; c=50; r1 = [a, b, c]; module rot_ang(p=[]) { rotate([0,0,p.z]) rotate([0,p.y,0]) rotate([p.x,0,0])children(); } module rot_angx(p=[]) { rotate([-p.x,0,0]) rotate([0,-p.y,0]) rotate([0,0,-p.z])children(); } color("green") cylinder(h=50); rotate(r1) color("orange") cylinder(h=50); rot_angx(r1)rot_ang(r1)color("red")cylinder(h=50); On Wed, 22 Mar 2023 at 08:50, Steve Lelievre < steve.lelievre.canada@gmail.com> wrote: > > On 2023-03-21 7:02 p.m., Adrian Mariano 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. > > Sure, but in my defense... I'm not actually doing vector math. I'm just > making an arrow that points off somewhere fairly random so that I can use > it to represent of a direction vector in a diagram drawn in the viewport. > > And actually, if I was worried about being exact, I would be starting from > angles anyway. This is for a celestial mechanics project and my information > about the Sun's position is its azimuth and altitude angles. The angle form > of rotate is a breeze for that: > > rotate([-altitude, 0, -azimuth]) arrow(); // negation due to sign > conventions of solar angles; arrow initially on south meridian > > > Steve > > > > > > 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 > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
L
larry
Wed, Mar 22, 2023 4:09 PM

On Wed, 2023-03-22 at 07:46 +0530, Sanjeev Prabhakar 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);

I modified in order to check the different colours.
Got a surprising (to me, at least) result.
I expected the orange cylinder to be displaced Y only.
Can you explain why this happened?

r1 = [30, 40, 50];
r2 = -r1/360;
color("green") cylinder(h=50);
rotate(r1) color("orange") translate ([0,10,0]) 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

On Wed, 2023-03-22 at 07:46 +0530, Sanjeev Prabhakar 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); I modified in order to check the different colours. Got a surprising (to me, at least) result. I expected the orange cylinder to be displaced Y only. Can you explain why this happened? r1 = [30, 40, 50]; r2 = -r1/360; color("green") cylinder(h=50); rotate(r1) color("orange") translate ([0,10,0]) 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
SP
Sanjeev Prabhakar
Wed, Mar 22, 2023 4:18 PM

Please don't take this seriously

This was just a prank looking at the expectation that there may be a
miracle formula.

I clarified later on that in openscad you have to rotate step wise only.

if you divide any number with any big number, the rotation is almost 0.

In your example you have shifted the 2nd cylinder (orange one) by 10 units
in y-axis, therefore it is showing at different place

3rd cylinder is rotated at its original location

On Wed, 22 Mar 2023 at 21:40, larry lar3ry@sasktel.net wrote:

On Wed, 2023-03-22 at 07:46 +0530, Sanjeev Prabhakar 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);

I modified in order to check the different colours.
Got a surprising (to me, at least) result.
I expected the orange cylinder to be displaced Y only.
Can you explain why this happened?

r1 = [30, 40, 50];
r2 = -r1/360;
color("green") cylinder(h=50);
rotate(r1) color("orange") translate ([0,10,0]) 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


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

Please don't take this seriously This was just a prank looking at the expectation that there may be a miracle formula. I clarified later on that in openscad you have to rotate step wise only. if you divide any number with any big number, the rotation is almost 0. In your example you have shifted the 2nd cylinder (orange one) by 10 units in y-axis, therefore it is showing at different place 3rd cylinder is rotated at its original location On Wed, 22 Mar 2023 at 21:40, larry <lar3ry@sasktel.net> wrote: > On Wed, 2023-03-22 at 07:46 +0530, Sanjeev Prabhakar 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); > > I modified in order to check the different colours. > Got a surprising (to me, at least) result. > I expected the orange cylinder to be displaced Y only. > Can you explain why this happened? > > r1 = [30, 40, 50]; > r2 = -r1/360; > color("green") cylinder(h=50); > rotate(r1) color("orange") translate ([0,10,0]) 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 > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
L
larry
Wed, Mar 22, 2023 4:29 PM

On Wed, 2023-03-22 at 21:48 +0530, Sanjeev Prabhakar wrote:

In your example you have shifted the 2nd cylinder (orange one) by 10
units in y-axis, therefore it is showing at different place
3rd cylinder is rotated at its original location

Ahh... I just now realized my error. The translate() should have been
before the rotate().

On Wed, 22 Mar 2023 at 21:40, larry lar3ry@sasktel.net wrote:

On Wed, 2023-03-22 at 07:46 +0530, Sanjeev Prabhakar 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);

I modified in order to check the different colours.
Got a surprising (to me, at least) result.
I expected the orange cylinder to be displaced Y only.
Can you explain why this happened?

r1 = [30, 40, 50];
r2 = -r1/360;
color("green") cylinder(h=50);
rotate(r1) color("orange") translate ([0,10,0]) 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


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

On Wed, 2023-03-22 at 21:48 +0530, Sanjeev Prabhakar wrote: > In your example you have shifted the 2nd cylinder (orange one) by 10 > units in y-axis, therefore it is showing at different place > 3rd cylinder is rotated at its original location Ahh... I just now realized my error. The translate() should have been before the rotate(). > On Wed, 22 Mar 2023 at 21:40, larry <lar3ry@sasktel.net> wrote: > > On Wed, 2023-03-22 at 07:46 +0530, Sanjeev Prabhakar 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); > > > > I modified in order to check the different colours. > > Got a surprising (to me, at least) result. > > I expected the orange cylinder to be displaced Y only. > > Can you explain why this happened? > > > > r1 = [30, 40, 50]; > > r2 = -r1/360; > > color("green") cylinder(h=50); > > rotate(r1) color("orange") translate ([0,10,0]) 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 > > > > _______________________________________________ > > 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