   What is a matrix for???
  I am working on a math api for game programming, and I've gotten to the Matrix class.  I have understood everything up to this point, Points, vectors, ect... but I do not understand matrices.  I have many books, and they all explain the same things.  How to add, subtract, multiply matrices.  How to do rotations, scale, ect...  But what I want to know is what is really going on, and I can't find any info.  Are the matrices really linear equations?  How could you do this stuff with paper and pencil without matrices.  What problem do these things solve.   Glass_KnifeI think, therfore I am. I think?[edited by - glass_knife on August 4, 2003 7:54:41 AM]
  A 3d transformation matrix defines how components of the parameter vectors affect the result vectors.take an unit transformation:1 0 00 1 00 0 1 x coordinate of the original vector affects 1 * x on the result vector. other coords don't affect the result's x because their coefficient is 0.y, on the other hand, has the y coefficient 1, while others are zero.repeat this for all components of the result vector, and you have the transformaed vector (which, on an unit transform matrix, is the same as the original vector).Some systems flip the notion of column/row on the matrices, be sure which convention you use!NikEDIT: typos, clarification   [edited by - Nik02 on August 4, 2003 8:35:19 AM];  >> Are the matrices really linear equations?A matrix M as such is no equation of course (no "="). Mathematically spoken a Matrix M is a linear map over a finite-dimensional (3D in your case) vector-space V. So think of a Matrix as a mathematical function (hope you know what that is; it´s quite close to a function in programing).If you have the equations u = M(v) (can also be written as u=Mv; u=M*v is less common) the first entry of u will be the vector product of the first line in M and v. Same is true for the 2nd and 3rd line. So in fact u=Mv is equivalent to a 3x3 linear equations system. For this reason matrices are also shortcuts for linear equations systems (what you propably meant by linear equation).>> How could you do this stuff with paper and pencil without matrices?Not sure what stuff you mean but if you speak of rotating, scaling, ... it´s done the other way round. First you determine what happenes when you say rotate your vector and then try to find a matrix that does this.>> What problem do these things solve?You can bring a lot of equations in a quite readable form. But since I guess you r question was more 3D-computing related I´ll give you another answer that I´m not 100% sure to be true but that sounds a logical reason why matrices are used in opengl, direct3d:Say you have a rotation-matrix around the x-axis X and a rotation-matrix Z around the z-axis. Now you want to rotate a lot of vectors around the x-axis: the resulting vectors are v' = Xv. This could easily be done with the corresponding linear equations system. Now you want to rotate all of the resulting points v' around the Z-axis afterwards. You get: v' = Z(v') = Z(X(v)). You actually have two matrix multiplication for each vektor v to determine v'. At this point a very usefull characteristic of matrices can be used: Z(Xv) = (ZX)v. You calculate ZX once and then only have one matrix multiplication for each vector. For that reason you usally first calculate the view-matrix by "primitive" operations and then apply the whole matrix to all points instead of transforming your vectors all through this process.That was quite a long answer for such a short question but your question is quite general and not really easy to answer because in the end matrices are just a way of writing things down like saying "x=5*n" instead of saying "each [dontknowwhat] costs you 5 dollars".    [edited by - Atheist on August 4, 2003 9:29:26 AM];  Thanks for the information.  The more I look at the matrix stuff, the more it makes sense.  I guess what is confusing is that math books show using a matrix to solve equations.  When I see matrix stuff in the 3D graphics arena, My first thought was that somthing was being solved.  In fact that is not the case.  The matrix is just another way of doing math to a vector, or maybe 3 vectors of a camera.  Is that right.  Let me see if I understand...Here is a transformation matrix...1  0  0  00  1  0  00  0  1  0dx dy dz 1multiply a vector [ x, y, z ] by the Matrix...V2 = V * M is the same as this...V2 = M(V) and both of these is really the same as doing this...V2 = [ x + dx, y + dy, z + dz ]the same goes for a rotation...rotate about the z axis... cos( theta )  sin( theta )  0  0-sin( theta )  cos( theta )  0  00   0   1  00   0   0  1Muliply that by a V [ x, y, z, w ]V2 = V * M  orV2 = M(V)  orV2 = [ x*cos(theta)-y*sin(theta), x*sin(theta)+y*cos(theta), z ]It''s the same thing, just a different way of doing things.  Is this correct?  Or am I still lost?   Glass_KnifeI think, therfore I am. I think? ;  if your vector v (in maths and especially in physics it´s common to take small letters for vectors and capital letters for matrices so you can see from the equation what is what but that´s only a convention of course and doesn´t affect the result) is a row-vector then you´re right. You´d write it as v*M instead of M*v in maths but that´s not really important. The convetion wheter vectors are rows or collums should depend on the library (as does the convention how the values of the matrix are stored).>> The matrix is just another way of doing math to a vector.Yup. The maths is limited to linear (or in case of a 4x4 matrix: affine-linear) operation, but that´s sufficient for most (all?) primitive geometric operations.>> It''s the same thing, just a different way of doing things.One can argue about that because it´s rather a different way of writing it down. It defenitely is the same thing and I´d say it´s even the same way of doing it. But: You got the point.btw.: I´ve never cared how my opengl actually computes because for me it´s sufficient to know it does. But tricking the matrices into doing translations by making them 4x4 instead of 3x3 (your first example) looks interesting and quite clever. ;  Matrices are an important facet of computer graphics in games etc, but matrices are used heavily in other areas to represent equation coefficients. If your API is open-ended enough, you may be able to utilise it in other areas of apllication. e.g. Blitz++.   Wizza Wuzza? 