Odyssey paper #08
31 марта 1999 |
|
Algorithms - a rotation in three-dimensional coordinate system. Matrix.
Algorithms _________ Prepared according to the foreign press. Rotations - Rotations ____________________ One thing that could look nice in our 3d world, would be rotations. Actually, rotations are what we use when doing camera, and rotation is also what we need to add if we want any object to move in any way. It would here, be an advantage to have learned or have the knowledge about sinus and cosinus, but if this is not the fact, then just try to hang on. There is one thing that helps us look like real 3D world is rotating. In fact, the rotation - that we use for camera movement and rotation - and that we should add, if we want to any object moving in any direction. It should be used to have the advantage to study or have knowledge about sines and cosines, but if it is - not so, then only trying to hang on (be aware of sin, cos). At first, lets look at 2d rotations. What we need here is to rotate a xy point around the two axis', or the point 0,0. This is done with the formulars: First, let's consider the 2D rotation. What we need to rotate the point xy around two axes, or point of 0.0? This is the formula: newx = x * cos (theta) - y * sin (theta) newy = y * cos (theta) + x * sin (theta) Now, we can see thatnewx equals x multiplied with cos (theta) and added y multiplied with sin (theta). Some might wanna ask why we have the y axis messed into the rotation of x, but thats actually pretty simple. The result newx have absolutely nothing to do with the origional x value, it is a product of x and y. Now, what we can see of the above formulars, we multiply with the current axis and add a multiply of the second axis. An example is given below: Now, we can see that newx equals x * cos (theta)-y * sun (theta). Some might ask why we are the y-axis mixed in rotation with x? It's pretty simple. Result newx has absolutely nothing to do with the original value of x, it - the product of x and y. Now that we have can see in the above formulas, we multiplied with the current axis and the added multiplying the second axis. An example is given below: x = 10 y = 0 angle = 45 newx = 10 * cos (10) - 0 * sin (10) newy = 0 * cos (10) + 10 * sin (10) newx = 9.85 newx = 1.74 Now, would we like to rotate around another point than 0,0 we have to subtract the value from the x and y point. This would look like this: Now, around each point, different from 0,0. We must subtract the value out of y and x. It looks like this: newx = (x-startx) * cos (theta) - (y-starty) * Sin (theta) + startx newy = (y-starty) * cos (theta) + (x-startx) * Sin (theta) + starty For an example, we want the point (7,0) rotated 180 degress around the point (6,0) Now, by decreasing our point by (6,0) we ' ve moved it into (1,0). If we rotate this by 180 degress it would return (-1,0) and this we add with our start x and y values to a final result of (5,0). A nice and correct result. But all of this have nothing to do with 3d rotations, so lets get on with that. For example, we want to point (7,0) turned 180 degrees around the point (6,0). Now, reducing our position to the (6, 0) we moved it to the (1,0). If we rotate it 180 degrees, it would return (-1,0), And that we add to our top x and y values to the final result (5,0). Good and correct result. Matrices - Matrix __________________ Matrices are used to simplify code and in most cases to make them faster.This we can see in our rotation code, where we use them to cut the normal 12 muls down to 9 muls. Now, lets look at the basics. In general matrices are just an array of number, which you give to a set of variables. Lets look at some of the matrices we use in the code. Matrix is used to simplify the code and in most cases, to make it faster. This we can see in our code rotation, where we use them to truncate the normal with 12 multiplications and 9 multiplications Now, let's look at the basics. General matrix - only the table numbers in which You have a lot of variables. Consider some of the matrices that we use in the code: [X '] [1 0 0-camerax] [x] [Y '] [0 1 0-cameray] [y] [Z '] [0 0 1-cameraz] [z] [1] [0 0 0 1] [1] This matrix is also called a 4x4 matrix, since it has four rows and coloums. Now, 4x4 and 3x3 matrices are the most common matrices in 3d programming, but they can ofcourse be found in any size. Now, what does the above matrix mean, and how do we get the right values and which variables do we change? Lets take a look. This matrix is called a 4x4 matrix, so it has four rows and columns. Now, 4x4 and 3x3 matrix - the most common matrix in 3D programming, but they can certainly be of any size. Now, that the above matrix means, and how we get the right values of the variables that change? Let's look. First we have the variables x ', y', z 'and the number 1. After that we have four set of numbers. Then we have the variables x, y, z and the number one again. Now, what we basicly do here is that we multiply the first row of the second part of the matrix with each of the variables in the thirds row, add them together and them give them to the variable in the first part of the matrix of that specific row. A better way to show this would be this: First, we have the variables x ', y', z ' and the number 1. After that, we have 4 sets of numbers. Then we have the variables x, y, z, and again the number 1. Now, we just do? We multiply the first row of the second part of the matrix with each of the variables in a row the third part, we add them together and is issued on the result of a variable in the first part of the matrix of this particular line. x + y + z + 1 * [X '] = [1 0 0-camerax] [Y '] = [0 1 0-cameray] [Z '] = [0 0 1-cameraz] [1] = [0 0 0 1] In this case every variable would have z value: In this case, each variable would be value: x '= a * x + 0 * y + 0 * z +-camerax * 1 y '= 0 * x + a * y + 0 * z +-cameray * 1 z '= 0 * x + 0 * y + a * z +-cameraz * 1 1 '= 0 * x + 0 * y + 0 * z + 1 * 1 Now this might be a little hasty to begin with, so lets take a look at some other way to explain matrices. Now, say we need to do the following: Now we will digress, to move on, so let's look the other way to explain matrix. Now, what we need, so do this: x '= 3x + 8y Or another way of saying this is: Or in another way: x '= ax + by Consequently, we can make a matrix: [X] x '= [a b] [y] Now, lets make this a 2x2 matrix instead of 2x1. Now, put a 2x2 matrix instead of 2x1. x '= 3x + 8y y '= 6x + 2y x '= [3 August] [x] y '= [2 June] [y] Now, we wish to do so: x '= 3x + 8y + 9 y '= 6x + 2y + 2 x '= [3 8 9] [x] y '= [6 2 2] [y] 1 '= [0 0 1] [1] As you can see, what we do is to take the third part and multiply the first row with the first coloumn, then add second row of the second part multiplied with the second coloumn, and so on. This should be very simple and easy to understand. As you can see that we take the third part and multiply the first row with first column, then add the number of multiplying the second row of the second part of the second column, and so on.
Other articles:
Similar articles:
В этот день... 21 November