Learning About Rotation

Started by
25 comments, last by Zakwayda 4 years, 10 months ago
15 minutes ago, Green_Baron said:

Your examples rotates a given matrix by 90° around the axis defined by the vector (1/0.5/0)

Right. So { 1.0F, 0.5F, 0.0F } represents an axis rather than the value that the angle should be multiplied by to get the final angle of rotation on each axis. Again I cannot conceptualise how a 3D vector could represent an axis. To me it seems that an axis is 1D, you need 3 axes (x, y, z) to represent 3 dimensions.

Anyway I am gonna spend the next few months working through some Khan Academy linear algebra and the interactive tutorial you provided. Maybe I will be able to understand your explanations a bit better! 

Advertisement
4 minutes ago, calioranged said:

Yes sorry I have my terminology wrong there.

What I mean is that if you have the following rotate matrix:



glm::mat4 rotator { glm::rotate(glm::mat4(1.0F), 
			        glm::radians(degrees), 
				glm::vec3(rotation.x, rotation.y, rotation.z)) };

MVP.view.direction = rotator * MVP.view.direction;

Where:

degrees = 90
rotation.x = 1.0F
rotation.y = 0.5F
rotation.z = 0.0F

Then the view direction will be rotated by:

90° on the x-axis (90 * 1.0)
45° on the y-axis (90 * 0.5)
0°   on the z-axis (90 * 0.0)

[Please correct me if the above is wrong] So rotation is not happening by the specified amount on one axis, it is happening by the specified amount on each axis.

 

 I think you are wrong ;) - I don't use GLM, I have my own implementation. Therefore I don't know the specific function you posted,  but I think they are not doing something to fancy there. What I guess it does is creating a matrix, that rotates everything  90 degrees around the axis (1, 0.5, 0)

So imagine yourself standing in a room. The x-axis is pointing into your view direction. The y-axis is pointing to your right, and the z-axis is pointing directly into the sky. You are the origin of this coordinate system. Each axis value at your location is 0.

Now think about an object directly in front of you. Let it be 2 meters away from you. So its location towards you would be described by the vector (2, 0, 0). If I tell you "please rotate by 90 degrees left" and you obey that command, the object would now be located 2 meters away on your right-hand side. So at (0, 2, 0). This is a rotation around the z-axis. What would have happened, if I told you to rotate around the y-axis? Point with your arm to your right-hand side (in direction of the y-axis) and imagine somebody grabs your arm and starts twisting it around 90 degrees. Okay, that might hurt, but imagine that instead of being hurt, your body is rotated. ;)  Depending on the direction of the rotation, the Object will end up being 2 m above your head or 2 meters below your feet. So at (0,0,2) or (0,0,-2). So now lets come back to the vector you specified: (1, 0.5, 0)

Point your arm directly in front of you. That would be (1,0,0). Now rotate your arm a little bit to the right, so that you are not pointing directly in front of you but also not totally to the right. The direction you are pointing to is now something like this (X, Y, 0). Now imagine again, what would happen if somebody grabs your arm and rotates you around 90 degrees. Okay, the outcome might be a little bit hard to imagine unless you try it out, but one thing for sure: Since you just rotated yourself and did not change your position, the distance between you and the object remains 2 meters! The vector, which describes the object's location towards your new orientation might now have three non-zero entries (X, Y, Z), but its lengths remain 2 meters. By the way, a vector's length is calculated by sqrt(X*X + Y*Y + Z*Z)

Hope that helped a little bit in understanding what is going on.

 

Greetings

Very good explanation @DerTroll. In OpenGL the y axis goes up and z goes into the depth, so the rotation in your example is around y for OpenGLers. I think this is different on Windows/D3D ? Just so that no new confusion is being introduced, nevermind ?

19 minutes ago, DerTroll said:

 I think you are wrong ;) - I don't use GLM, I have my own implementation. Therefore I don't know the specific function you posted,  but I think they are not doing something to fancy there. What I guess it does is creating a matrix, that rotates everything  90 degrees around the axis (1, 0.5, 0)

So imagine yourself standing in a room. The x-axis is pointing into your view direction. The y-axis is pointing to your right, and the z-axis is pointing directly into the sky. You are the origin of this coordinate system. Each axis value at your location is 0.

Now think about an object directly in front of you. Let it be 2 meters away from you. So its location towards you would be described by the vector (2, 0, 0). If I tell you "please rotate by 90 degrees left" and you obey that command, the object would now be located 2 meters away on your right-hand side. So at (0, 2, 0). This is a rotation around the z-axis. What would have happened, if I told you to rotate around the y-axis? Point with your arm to your right-hand side (in direction of the y-axis) and imagine somebody grabs your arm and starts twisting it around 90 degrees. Okay, that might hurt, but imagine that instead of being hurt, your body is rotated. ;)  Depending on the direction of the rotation, the Object will end up being 2 m above your head or 2 meters below your feet. So at (0,0,2) or (0,0,-2). So now lets come back to the vector you specified: (1, 0.5, 0)

Point your arm directly in front of you. That would be (1,0,0). Now rotate your arm a little bit to the right, so that you are not pointing directly in front of you but also not totally to the right. The direction you are pointing to is now something like this (X, Y, 0). Now imagine again, what would happen if somebody grabs your arm and rotates you around 90 degrees. Okay, the outcome might be a little bit hard to imagine unless you try it out, but one thing for sure: Since you just rotated yourself and did not change your position, the distance between you and the object remains 2 meters! The vector, which describes the object's location towards your new orientation might now have three non-zero entries (X, Y, Z), but its lengths remain 2 meters. By the way, a vector's length is calculated by sqrt(X*X + Y*Y + Z*Z)

Hope that helped a little bit in understanding what is going on.

 

Greetings

In OpenGL; +X is to the right, +Y is up and +Z is coming out of the screen towards the viewer. 

That makes it rather difficult for me to picture what you have just explained being that the axes would all be in a different order. 

When you say 'please rotate by 90 degrees left', I'm not sure what you mean. From my understanding, rotation occurs on a particular axis so maybe you mean rotate on the y-axis (OpenGL y-axis) but I'm not sure. 

I am very grateful for your explanations but to be honest I am just not grasping them at all. I think I need to do much more on the basics before reviewing what you have said again. 

P.S. How can an axis be 3D?

10 minutes ago, calioranged said:

P.S. How can an axis be 3D?

Trivially, by having 3 components, a vector describes a point in 3 dimensional space. But a vector can also describe the line between the centre and a point in 3 dimensional space. This line can be seen as an axis around which all the other points must be rotated. By this rotation, they keep their distances from the rotational axis, but are translated by an angular amount.

You can have a look at glm's rotate function in 'glm/gtc/matrix-transform.inl'.

Do the tutorial, and get the red and blue books. Both come with their own math library that you can study as well.

2 minutes ago, Green_Baron said:

Do the tutorial, and get the red and blue books. Both come with their own math library that you can study as well.

Thanks for all of your help. 

3 minutes ago, calioranged said:

In OpenGL; +X is to the right, +Y is up and +Z is coming out of the screen towards the viewer. 

That makes it rather difficult for me to picture what you have just explained being that the axes would all be in a different order. 

When you say 'please rotate by 90 degrees left', I'm not sure what you mean. From my understanding, rotation occurs on a particular axis so maybe you mean rotate on the y-axis (OpenGL y-axis) but I'm not sure.

 

Well, essentially for the example I gave you, the names of the axis do not really matter. Just do literally what I told you. Take a bottle of coke or something else in front of you. If I say turn left by 90 degrees, do it. So where is the bottle now? to your right! So no x, y or z-axis involved in that example. You have just turned around your longitudinal axis, correct? See here:

http://www.odec.ca/projects/2009/kirk9j2/background_research.htm

I named that axis z, but you can also name it y to stick with OpenGL notation. So if you point your arm into the sky, it would be aligned with this axis and if somebody grabs your arm and twist it to the left, the thing described above will happen. If you point to the right, your arm is aligned with the frontal axis. Rotating 90 degrees around this axis will put you on the back or your belly and the bottle is now located under your feet or over your head. So far you have just rotated when your arm points into the direction of one of the coordinates systems axes. This means that your rotation vector has only one non-zero entry. But the mechanism stays the same, regardless of where you are pointing. Your arm will be twisted around 90 degrees and your body follows as if you were a stiff doll. Maybe you should get an action figure or something similar to try it out ?

I mean, it is only 3d. It is not anatomy. ?

?

 

 

1 hour ago, DerTroll said:

Well, essentially for the example I gave you, the names of the axis do not really matter. Just do literally what I told you. Take a bottle of coke or something else in front of you. If I say turn left by 90 degrees, do it. So where is the bottle now? to your right! So no x, y or z-axis involved in that example. You have just turned around your longitudinal axis, correct? See here:

http://www.odec.ca/projects/2009/kirk9j2/background_research.htm

I named that axis z, but you can also name it y to stick with OpenGL notation. So if you point your arm into the sky, it would be aligned with this axis and if somebody grabs your arm and twist it to the left, the thing described above will happen. If you point to the right, your arm is aligned with the frontal axis. Rotating 90 degrees around this axis will put you on the back or your belly and the bottle is now located under your feet or over your head. So far you have just rotated when your arm points into the direction of one of the coordinates systems axes. This means that your rotation vector has only one non-zero entry. But the mechanism stays the same, regardless of where you are pointing. Your arm will be twisted around 90 degrees and your body follows as if you were a stiff doll. Maybe you should get an action figure or something similar to try it out ?

Thanks for the extra detail you just went into just there.

I can picture all this just fine. What I cannot picture is a situation where there would be more than one non-zero value in the rotation vector - and how this would affect the viewing direction.

22 minutes ago, Green_Baron said:

I mean, it is only 3d. It is not anatomy. ?

?

 

Sorry that I am having a harder time grasping this than you would expect. If it is frustrating to you then I wouldn't be at all offended if you didn't write back, you have tried to help as much as you can. I am trying my best but I appreciate that I am a slow learner without much intuition. Sorry.

I was just joking. No problem, mate. Not at all. No need to apologize.

It is good for me as well, because as i answer i have to think some things through anew. The next step will be to think in different coordinate systems and juggle things between them. @DerTroll is right imo pointing out that axes names don't matter that much. Well they do matter in the code.

I am just a little stuck converting planet size stuff from world to view coordinates and from double precision to GPU friendly float. That's where my brain snaps shut at the moment. I know that in principle it is not too difficult, i have a text before me describing things, but still ...

This topic is closed to new replies.

Advertisement