# How can I rotate Euler angles through a specific angle?

• pizzanakin
In summary, the conversation discusses a problem with rotating objects around a specific angle using euler angles, specifically in the context of creating a plugin for the game Minecraft. The user is having difficulty translating coordinates and accounting for the rotation of the object's anchor point. They have found a similar topic on a forum but are still seeking more insight and are hesitant to fully understand the solution provided. They also mention having achieved their goal for one type of object but are having trouble with another due to a default rotation applied to the object.
pizzanakin
TL;DR Summary
I found an old topic on this forum that describes a similar problem to what I am facing currently. I want to rotate an object with euler angle values, but the rotation has to be translated based around a specific angle. However, I do not fully understand the solution provided in that topic, or how I can apply it to my situation. So I hope to get some more insight here.
Summary: I found an old topic on this forum that describes a similar problem to what I am facing currently. I want to rotate an object with euler angle values, but the rotation has to be translated based around a specific angle. However, I do not fully understand the solution provided in that topic, or how I can apply it to my situation. So I hope to get some more insight here.

Hello, I found these forums after I stumbled upon this topic through google:
https://www.physicsforums.com/threa...s-into-rotation-around-arbitrary-axis.201045/
This topic, although it seems to be quite old, sounds like a description of the problem I am having. However, I do not really understand what is described, so I was hoping to get some more insight from anyone here.

I will try to explain my problem in as much detail as possible, so that hopefully someone can guide me through it.

I'm making a plugin for the game called minecraft, which will allow me to add special displays into the game. This essentially comes down to placing so called 'Armor Stand' entities into the game. These entities can have their limbs placed in specific orientations, and they can display blocks on these limbs. I can use both mechanics to display any block in any rotation that I want, even with different sizes.

Here you can see an armor stand, and how the rotation of all limbs can be manipulated. The armor stand can wear blocks on its head and in its hand, which are the mechanics that I use to display blocks. I can even rotate the blocks by rotating the neck or arm. By turning the armor stand itself invisible, only the blocks remain visible to players.

My goal is to write my plugin in such a way that I can enter a specific location with a rotation, and that the block will appear exactly on that spot with that location. I have achieved that goal for the armor stands with blocks on their neck. But for the armor stands with blocks on their arm, the problem is a bit more difficult. I will tell you about my current problems and solutions so far:

The first problem that I had was that the 'transform' of the block (AKA the location reference to the block that I have in my code) is not actually at the center of the block, but at the feet of the armor stand (as you can see in the last image above, the green/red/blue lines). This is because I cannot directly reference the block itself, but I can only refer to the armor stand. This means that if I want to place a block at location (100, 64, 100), I would actually have to translate those coordinates based on the distance from the neck to the feet (1.4375) making it (100, 62.5625, 100).

The next problem was that the anchor of the neck rotation is at the point where the neck meets the chest, but the center of the block is placed on the top of the neck. This means that when I add a rotation to the block, it will also be slightly displaced from the coordinates that I give it. I added another translation to the coordinates that accounts for this, using a cos and sin function on the rotation values of the neck in order to move it the right amount. I achieved this mostly by trial and error, which means that I somewhat understand how it works, but I don't necessarily understand why it works.

Here is my code with these solutions:

The top line is used to create the armorstand itself, and the head position receives the pitch/yaw/roll values that I want. Then I calculate the radians of pitch and roll, and I use those to get the translation with sin and cos. I think 0.25 represents the length of the neck, so it basically creates a vector in the opposite direction of the neck, and it adds -1.4375 for the basic armor stand length.

These two solutions are all that is necessary to achieve my goal for the armor stands with blocks on their necks. However, the block that is placed on the arm has a default rotation applied that is different from the base rotation of the arm itself. This makes it harder to use, because I cannot directly apply translations based on the arm rotations to achieve the correct result.

The reason this doesn't work can be seen in the pictures above. First I add a rotation to the arm that cancels the default rotation of the block, so that it appears straight. From this point, I can easily rotate the yaw and the roll of the arm, and I could use cos and sin to make translations to place the block at the correct location. However, as soon as I attempt to rotate the pitch value of the arm, it doesn't correctly apply it to the block because it is actually still rotated with a 45 degree angle relative to the arm. I want to find a way that allows me to calculate a specific rotation for the arm that will result in a proper looking pitch rotation of the block when it is placed in the arm, as seen in the last picture.

I somewhat have an idea in my head of what that approach would be like, based on the topic that I've found mentioned above. Instead of my current approach, which is: correcting the default block rotation with the rotation values of the arm, and then adding the desired block rotation on the arm, I will have to do something along the lines of this:
- get a base vector that goes up from the block when it's rotation is corrected and have a euler angle that will rotate this vector to the specific rotation of the arm that gives the block that position.
- Then, I get a euler angle that will rotate the base vector of the block to my desired rotation of the block, and I combine this euler angle with the one that calculates the arm position.
I think that by applying the result of that, I can place the arm in the specific rotation that results in the initial eular angle values for the block. Once I have done all that, I can translate the coordinates of the armor stand based simply on the rotation values which I've entered for the arm.

However, I currently can't seem to move forward with this idea. It doesn't seem to crystallize further, which makes me think there's something wrong with it, or maybe I just don't know the right approach. Based on my current code, I would have to do some alterations to the pitch/yaw/roll values that are entered for the arm position. Can anyone point me towards what kind of calculations those would be, based on the info I've given in this post?

## 1. What are Euler angles and why are they used for rotation?

Euler angles are a set of three angles that describe the orientation of an object in three-dimensional space. They are commonly used in robotics, computer graphics, and aerospace engineering to represent rotations because they provide a simple and intuitive way to describe the rotation of an object.

## 2. How can I convert Euler angles into a rotation matrix?

To convert Euler angles into a rotation matrix, you can use the following formula:

R = Rx * Ry * Rz

Where Rx, Ry, and Rz are rotation matrices around the X, Y, and Z axes respectively. The resulting rotation matrix can then be used to rotate a point or object by multiplying it by the rotation matrix.

## 3. Can I rotate Euler angles through any angle?

Yes, Euler angles can be rotated through any angle, as long as the rotation is around one of the three axes (X, Y, or Z). This is because Euler angles are based on a three-dimensional coordinate system and can represent rotations in any direction.

## 4. How do I know which Euler angles to use for a specific rotation?

This depends on the type of rotation you want to achieve. If you want to rotate around a single axis, you can use a single Euler angle. If you want to rotate around multiple axes, you will need to use a combination of Euler angles. It is important to note that there are multiple ways to represent the same rotation using Euler angles, so it is essential to understand the convention being used.

## 5. Are there any limitations to using Euler angles for rotation?

One limitation of using Euler angles is that they are prone to gimbal lock, which occurs when two of the angles align, resulting in a loss of one degree of freedom. This can cause unexpected behavior when rotating an object. Additionally, the order in which the rotations are applied can affect the final orientation, so it is crucial to use the correct order when rotating objects with Euler angles.

Replies
2
Views
4K
Replies
1
Views
1K
Replies
7
Views
1K
Replies
18
Views
1K
Replies
6
Views
1K
Replies
4
Views
2K
Replies
5
Views
1K
Replies
8
Views
2K
Replies
2
Views
2K
Replies
1
Views
759