How can I rotate Euler angles through a specific angle?

  • Thread starter pizzanakin
  • Start date
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:

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.

246314

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:
246323

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.

246317

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?

Thanks in advance!
 

FactChecker

Science Advisor
Gold Member
2018 Award
4,979
1,748

Want to reply to this thread?

"How can I rotate Euler angles through a specific angle?" You must log in or register to reply here.

Related Threads for: How can I rotate Euler angles through a specific angle?

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving
Top