I Rotate a shape back to its original position with the fewest rotations

kolleamm
Messages
476
Reaction score
44
TL;DR Summary
Rotate a shape back to it's original position with the least amount of rotations.
Summary: Rotate a shape back to it's original position with the least amount of rotations.

Lets say you have a cube. It's starting rotation is (0,0,0).
It can be rotated on each axis ( x,y,z ) no more than once each by 90 or -90 degrees
(rotation can also be skipped for any axis).

The shape has been rotated and the movements are unknown (its new rotation is known).
What method/algorithm could be used to determine the least amount of movements required to put it back to it's original rotation (0,0,0)?
(multiple solutions are allowed)
Rotations must happen sequentially.

My best guess is iterating through each possibility, but there has to be a better solution. This is related to animation.

Thanks in advance
 
Physics news on Phys.org
If the rotations are limited to 90 degrees, it seems like the (worst case) minimum number would be 2 + 2 +2 = 6.

EDIT -- added "worst case" parenthetical comment
 
Last edited:
  • Like
Likes sysprog
Perhaps misunderstand but have you looked up Euler angles?
 
  • Like
Likes Nik_2213
If you know which way it faces now, and which way it must face, surely you only need one (1) compound rotation, twirling it non-orthogonally ??

Matrix math makes it trivial, but I remember doing this using XYZ light-years and compound angle formulae for a 3D Astronomy program in FP BASIC on an Apple ][+. The poor little 6502 CPU was totally maxed out: Even compiling the program made scant difference...
 
  • Like
Likes sysprog
Maybe I misunderstand what you aim for, but if you are talking about combining a series of free rotations of a solid object in 3D space into a single rotation around a single axis, then this is always possible as per Eulers rotation theorem.

If you are new to rotations and are looking for a practical way to combine a sequence I will suggest you look at rotation matrices, as they are conceptually very easy to work with. Using these, any rotation around any axis can be written up as a 3x3 matrix and a sequence of such rotations is then represented by the 3x3 you get by multiplying all these matrices together. Note that order of multiplaction is important. Once you have the combined rotation matrix you can then convert it back to a single axis and angle.
 
  • Like
Likes sysprog, kolleamm and Nik_2213
Thank you all for your response.
Basically my problem is that I have a robotic arm and each axes of rotation is controlled by a motor.
I have no idea how to convert Euler angle rotational data to rotational instructions for each motor.

Please see the image.
 

Attachments

  • FullSizeR(29).jpg
    FullSizeR(29).jpg
    29.7 KB · Views: 357
kolleamm said:
I have no idea how to convert Euler angle rotational data to rotational instructions for each motor.

You may want to research the topic of forward kinematics. All my textbooks (and knowledge) on robotics are age old so I do not have any online reference on the topic. Perhaps others know of a good reference?

Also, if you are to provide command instructions to an actual robotic arm (as opposed to "just" doing the math part), then you obviously also need to research a lot of other topics.
 
The first thing you need to do is use a standard right-handed coordinate system!
If you can do matrices then you should take the trouble to understand Euler rotations. You know that the fundamental problem is that these operations are non commuting (i.e the order of operations matters). There are a variety of ways to approach this problem and the best solution depends upon the entire system. To solve your original question is a textbook exercise.

Edit: Please ignore the first sentence (I got snared in an optical illusion)
 
Last edited:
  • Like
Likes sysprog
What if I want to simulatenously rotate all axes towards this position? I've been thinking about this for a while, I really can't seem to find a solution. You adjust one axes and it just screws up the other.
 
  • #10
kolleamm said:
What if I want to simulatenously rotate all axes towards this position? I've been thinking about this for a while, I really can't seem to find a solution. You adjust one axes and it just screws up the other.
Welcome to noncommutivity.
Presumably you have an algorithm to go from some known position to where you want to be? If so you can always exactly reverse it.
Other than the motors do you have feedback about the orientation?

Look up infinitesimal rotations and see if it gives you any ideas. You won't figure this out strictly by fiddling. The Euler prescription always does finite rotations in a given sequence. There is nothing easier for the general case. Maybe your specific requirements are less general but you give no indication. This is not a trivial problem!
 
  • Like
Likes sysprog
  • #11
hutchphd said:
Welcome to noncommutivity.
Presumably you have an algorithm to go from some known position to where you want to be? If so you can always exactly reverse it.
Other than the motors do you have feedback about the orientation?

Look up infinitesimal rotations and see if it gives you any ideas. You won't figure this out strictly by fiddling. The Euler prescription always does finite rotations in a given sequence. There is nothing easier for the general case. Maybe your specific requirements are less general but you give no indication. This is not a trivial problem!
Currently the only information I have is two 3d vectors, and their Euler angle rotations.
I did look up infinitesimal rotations
and if I understand correct it attempts to use matrices to solve a transformation?

I did come up with a possible solution in the meantime. Assuming each axis can only have 360 degrees max and there are 3 axes, I could quite simply iterate through all the possible combinations to find the most matching 3d matrix.
(0,0,0) ; (0,0,1) ; (0,0,2) ... (360,360,359) ; (360,360,360);

360 x 360 x 360 = 46,656,000 combinations which a computer could solve and find the closest matching one.
 
  • Haha
Likes sysprog
  • #13
kolleamm said:
Currently the only information I have is two 3d vectors, and their Euler angle rotations.
I did look up infinitesimal rotations
and if I understand correct it attempts to use matrices to solve a transformation?

I did come up with a possible solution in the meantime. Assuming each axis can only have 360 degrees max and there are 3 axes, I could quite simply iterate through all the possible combinations to find the most matching 3d matrix.
(0,0,0) ; (0,0,1) ; (0,0,2) ... (360,360,359) ; (360,360,360);

360 x 360 x 360 = 46,656,000 combinations which a computer could solve and find the closest matching one.
Why 359 instead of 360?
 
  • #14
Look this is not that hard.

I'm confused by the drawing. You have two sets of coordinates labelled identically the same. Put primes on the object axes!

How does motor 3 differ from motor 2 ? If motor 3 rotates about y' then this problem is nearly trivial using Euler's angles.
 
  • Like
Likes sysprog
  • #15
hutchphd said:
Look this is not that hard.

I'm confused by the drawing. You have two sets of coordinates labelled identically the same. Put primes on the object axes!

How does motor 3 differ from motor 2 ? If motor 3 rotates about y' then this problem is nearly trivial using Euler's angles.
What about time?
 
Last edited:
  • #16
sysprog said:
What about time?
I seems like you would need to do them sequentially. But that can't be true...the end point has to be unique. I think the motors just spin to the calculated angle however they want...
 
  • Like
Likes sysprog
  • #17
hutchphd said:
I seems like you would need to do them sequentially. But that can't be true...the end point has to be unique. I think the motors just spin to the calculated angle however they want...
Please let us remember stepping motors -- discrete, continuous, etc.?
 
  • #18
Actually the sequencing is subtle. I think motor 3 would have to be connected to motor 2 which is connected motor 1 which is connected to the lab for Euler to be exact. I don't think the motor matters so long as it rotates under control.
 
  • Like
Likes sysprog
  • #19
hutchphd said:
Look this is not that hard.

I'm confused by the drawing. You have two sets of coordinates labelled identically the same. Put primes on the object axes!

How does motor 3 differ from motor 2 ? If motor 3 rotates about y' then this problem is nearly trivial using Euler's angles.
You were right, that was a drawing mistake I put the motor on the wrong axis
 
  • #20
The motors are servo motors in this case.
I was able to solve the problem after all. I will explain it below.

Short answer -- you assign each axis a plane (front,side, top), then you align one visible axes at a time with a matching axis on the other vector from these viewpoints.

Long answer --

1.You have two 3D vectors, one for the starting rotation (start vectors)
and the other for the next rotation (next vectors).

2.You take the start vectors and align them with the global vectors so it's now straight on every world axis.

3.You establish 3 world planes, front,side,and top, and assign the appropriate x,y,z axes to each one.

4.You look at the "next vectors" from each global plane, if it's vector(assigned for that plane) is visible with a length greater than 0 you rotate it such that that vector lines up with the same axis vector on the start vector.

5.Repeat for all other planes and keep track of the 3 angles that you rotated the next vectors by.I tested this out and it works really nicely. It did take several hours of coding but it does work.
 
  • #21
kolleamm said:
Thank you all for your response.
Basically my problem is that I have a robotic arm and each axes of rotation is controlled by a motor.
I have no idea how to convert Euler angle rotational data to rotational instructions for each motor.

Please see the image.
I am going to try to answer your original question - as I understood it. It sounded as though only 90-degree rotations were allowed.
Using a rotation matrix, I will call the home position of your cube: (1,0,0; 0,1,0; 0,0,1)
A count of all possible rotations can be calculated by noting that:
-- the first row of the rotation matrix for any cube position can be any of six values: 1,0,0; -1,0,0; 0,1,0; 0,-1,0; 0,0,1; and 0,0,-1.
-- for any given first row, the second row has a choice of two positions that can be non-zero, the tow that were left as zero in the first row; and that none zero value can be either +1 or -1. So there will always be four choices.
-- once the first two rows are specified, the third row will be non-zero in the only only column that remains zero; and its value will be plus or minus one. But only one of those two choices will work - the other will produce a mirror image of the cube that cannot be corrected by rotations.

So the total number of positions is 6x4 = 24

There are six possible rotations: x, y, or z - each in either of two directions.

When these six rotations are applied to the original cube position, six unique positions are generated. So with 0 or 1 rotation, the total number of unique positions is 7.
When those six rotations are applied to those 6 new positions, an additional 11 unique positions are discovered - totaling 18.
When those six rotations are applied to those 11 new positions, an additional 6 unique positions are discovered - totaling 24.

Thus, as many as three rotations are required to correct some cube positions.
The positions that require 3 rotations are:

#19
0 0 1
0 -1 0
1 0 0

#20
0 0 -1
0 -1 0
-1 0 0

#21
0 1 0
1 0 0
0 0 -1

#22
0 -1 0
-1 0 0
0 0 -1

#23
-1 0 0
0 0 -1
0 -1 0

#24
-1 0 0
0 0 1
0 1 0
 
  • #22
I just noticed: this thread is about 8 weeks old.
I don't know how it got my attention.
 
Back
Top