Jump to content

  • Log In with Google      Sign In   
  • Create Account

How do Rotation Matrix Work?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 vaironl   Members   -  Reputation: 128

Like
0Likes
Like

Posted 13 November 2012 - 08:11 PM

Hello everyone,

I saw a couple of articles on wikipeadia and other places about rotating shapes using Matrix.

I do not have much experience with Matrix in general, but I can do my reasearch.

Now the thing that I would love to make is, kind of my own rotating shape, from scratch in java.
I mean drawing everything without any help from any library and then using a rotational matrix (Sorry if the name is wrong!) and make a 3D picture. I already have done 2D graphics.

I would just love to go through the work and understand how exactly it works.

Thanks for the help, if possible.

Sponsor:

#2 Burnt_Fyr   Members   -  Reputation: 1249

Like
0Likes
Like

Posted 14 November 2012 - 10:36 AM

A matrix is used to transform vectors from one space to another. So if your model is built in its own coordinate system, we can use the tranform to move it's local position to a relative one in another coordinate system. We can also invert the process, taking vectors from another coordinate system, and transform them into local coordinates.

Generally, an object will have it's vertices defined in local space. These vertices can be moved into a common space, often called "world" space, by using a transform.
For an example, take a unit cube, centered at origin. It's vertices will have coordinates ranging from -0.5 to +0.5 in each axis, XYZ. If we want to make a cube at <6,0,0> in world space, we take each vertiex and multiply it by a transform matrix, resulting in world space vertices ranging from +5.5 to +6.5 on the x axis.

A camera is simply another object in space, and we can use the second point in the first paragraph, to translate the world space vectors into the cameras local frame, often called view space. Continuing with the example above, If we want to view the cube, we could make a camera, and set it at origin, but looking down the X axis. The cameras world transform would transform the local XYZ axes to the world , so that the local Z axis is aligned with the world X, and the local X axis would be aligned with the world -Z. The inverse of that transform will take the world space vertices of the cube, and transform them into view space. Our cube in view space would now have x and y coords ranging from -0.5 to +0.5, with it's Z coordinates ranging from 5.5 to 6.5.

finally, projecting the 3d view space coordinates into screen space can be done with whats known as a projection matrix, so that objects farther back appear smaller and so forth. this would make the far side of the cube slightly smaller than the near side.

I would suggest finding a good resource such as http://www.euclideanspace.com/ to get a better, more visual idea of what is going on. When I first learned about matrices it made 0 sense to me. Thanks to the explanations Martin Baker gave, I was able to piece together a basic 3d renderer in PHP, which gave me enough confidence to start tackling DirectX and I'm still going strong.

#3 Xcrypt   Members   -  Reputation: 154

Like
0Likes
Like

Posted 15 November 2012 - 05:59 AM

Hello. To understand a transformation matrix, you must first understand transformation. This is all trig:
http://www.khanacademy.org/math/trigonometry/v/polar-coordinates-1 Check the ones on polar coordinates.

Once you understand that, you should know that rotation matrices are just a fancy way of doing those operations. Matrices are just used for performance, you do not need them to implement transformation. There are many people who get introduced to matrices before they even know (or they forgot) how transformation works, and because of that many people find the concept confusing.

Edited by Xcrypt, 16 November 2012 - 04:34 AM.


#4 Beem   Members   -  Reputation: 127

Like
-1Likes
Like

Posted 18 November 2012 - 08:46 PM

I hate to be the bearer of bad news, but all you really need to know right now, is that nobody knows what the matrix is. If you multiply two of them together it catenates them and then both transformations will occur. The reason you can do this is because 4x4 matrix with multiplication and addition defined as we normally do form a ring. In a ring multiplication is associative, so it matters not which matrices gets multiplied when, but only that they are properly pre-multiplied or post-multiplied depending on what you want to accomplish. For now just follow the formulas that tell you how to form the matrix, where to put the cosine and sine of the angles, and you'll have to be careful about transposes, since some graphics libraries use row vectors and some use column vectors. With row vectors, you post multiply by the matrices, with column vectors you pre multiply them, and when you switch from one to the other you must transpose the matrices. This will potentially cause for the most confusion.

The best way to think of matrices as some kind of black box, a function, that takes a vector as an input and ouputs a vector that has been transformed. With 4x4 matrices, which is what he use in video games, because they allow us to use the magical homogenous transormation, the input will be a 4x1 vector. Just set the w component to 1 for positional transformations, and you're good to go. Don't worry about setting w to antyhing else.

Now the reason I said I had bad news, is because if you truly want to understand matrices, you got to go to college to learn about linear algebra. I'm sorry to say it, but without a strong mathematical background if you tried to just read about matrices you'd think they are just some mystical force in the universe that somehow just work. There are all sorts of interesting reasons why we can pull off what we do in video games using matrices, such as orthogonal transformations, and the like, but it really takes a strong mathematical background to get understand it.

I will say this, however, if you get a degree in mathematics, you can still get a job in video games, and also since you have a degree in math and not computer science, people won't ask you to fix their computers all the time cause they don't know you know about computers.

#5 Nypyren   Crossbones+   -  Reputation: 4824

Like
0Likes
Like

Posted 18 November 2012 - 09:32 PM

Rotation matrices work by using the matrix form of simple trig identities for angle addition:

http://en.wikipedia.org/wiki/Trigonometric_identity#Angle_sum_and_difference_identities


As far as 3D geometry matrices go, they aren't mystical at all. Think of them as four vectors packed together. During multiplication with other matrices or vectors, the first three "vectors" inside the matrix modify the coordinate axis (X,Y,Z) directions, and the last one modifies where the "origin" is. In this form, a matrix "converts coordinate spaces".

You can render the contents of a matrix to the screen and visualize it by splitting the matrix down into each vector and then using those to plot lines on the screen. If you were to render a standard 3D model using the matrix, you would notice that it would be rendered at the same position and orientation as the three lines.

#6 Cornstalks   Crossbones+   -  Reputation: 6991

Like
0Likes
Like

Posted 18 November 2012 - 09:47 PM

Now the reason I said I had bad news, is because if you truly want to understand matrices, you got to go to college to learn about linear algebra. I'm sorry to say it, but without a strong mathematical background if you tried to just read about matrices you'd think they are just some mystical force in the universe that somehow just work. There are all sorts of interesting reasons why we can pull off what we do in video games using matrices, such as orthogonal transformations, and the like, but it really takes a strong mathematical background to get understand it.

Some matrix operations may require college-level linear algebra to understand, but rotation certainly isn't one of them. 8th grade math was all I needed to understand them...

@OP: Do you understand how 2D rotation matrices work? It's much easier to understand 3D rotation matrices if you understand 2D rotation matrices, but I don't want to go over 2D matrices if you're already familiar with them, and I won't talk about 3D rotation matrices if you don't understand 2D rotation matrices.

Also, you said you haven't done much with matrix math. I suggest you check out the Khan Academy to learn about matrix math. Start with the first video. I suggest watching the first 9 videos. The others are optional, as far as understanding rotation matrices goes.
[ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS