Points, vectors, matrices

This is a discussion on Points, vectors, matrices within the Game Programming forums, part of the General Programming Boards category; I'm having real trouble making this correlation. I know what points and vectors are in definition. What I don't understand ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    47

    Points, vectors, matrices

    I'm having real trouble making this correlation. I know what points and vectors are in definition. What I don't understand is, from what I can tell, you write a point as x,y,z and you write a vector as x, y, z. This is puzzling, since vectors have a magnitude and direction. How can I tell that from x,y,z?

    Right along with this is the difference between vectors and real values. Are real values points? I know dot products give you real values, and cross products give you another vector.

    Next is vectors to matrices. How a vector becomes a 3x3 matrix or what is contained in a 3x3 matrix is beyond me. And yes, I have books. They detail formulas out very nicely. But the holes in their explanations are described above. I mainly see sections on points, vectors, and matrices. But not how they go together or even if they do.

    This may be a lot of questions for one post, but then again, they may all get answered in one sentence. I don't know. If you know the answer to any or all, please point me in the right direction.
    subnet_rx

    "There are two types of langages, those that everyone *****es about, and those that no one uses."
    Last edited by subnet_rx; 01-02-2002 at 07:59 PM.

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    Hmm, I hope I correctly understand what you're asking here.

    From any vector in n dimensions, you can represent the magnitude of that point with one dimension, and the direction in in n-1 directions. For example, we might change the expression...

    (3, 4) (Cartesian)
    to
    (5, ACOS(3 / 5)) (Polar)

    These are how we traditionally represent vectors, although really any means that we can use as acceptable. For example, we might not want to use the ACOS(), we could just as well use...
    (5, 3/5) (Fantasy System)
    Which obviously conveys as much information as the prior ones (although such a system might have difficulty representing say, a .1degree angle)

    For 3-dimensional coordinates, we do largely the same thing...

    (2, 3, 6) (Cartesian)
    to
    (7, ACOS(2/7), ACOS(3/7)) (Polar)

    From any point, we can get a direction, and how many dimensions it takes to represent that direction is the number of dimensions of the point - 1

    But that is all just coordinate systems. A vector doesn't have to be a magnitude and a direction, just as a point doesn't have to be rectangular coordinates. The only real difference in points and vectors is how they are used. For example, in telling the temperature, we would use a one-dimensional point...

    It is 75 degrees outside. (This is a point, 75)

    The temperature difference between outside and inside is 20 degrees. (This is a vector, 20)

    The difference between a point and a vector really is just a matter of context. You can change all your points to vectors from the origin and it won't make an ounce of difference.


    As for matrix multiplication and vectors... well, let's say I have a pyramid (4 sides, 4 corers) figure that I want to represent as 4 vectors (each vector will be pointing at a corner) These are the vectors...
    (2, 3, -5),
    (-2, 5, 6),
    (1, -4, 4), and
    (3, 4, -5)

    Notice that having the vectors point at the corners is one way in which we can represent any polygon as a set of vectors.

    Now if I want to turn this set of 4 3-dimensional vectors into a matrix, I just represent them vertically and put 'm next to each other...
    Code:
    //Matrix here...
    ( 2, -2,  1,  3)
    ( 3,  5, -4,  4)
    (-5,  6,  4,  5)
    // Each column is a vector, read from top to bottom
    The whole point of organizing vectors as a matrix is so that we can perform some operation on all the vectors at the same time, and thus be performing that operation on the polygon. Matrix multiplication only allows us to really add and multiply, but addition and multiplication is all that you really need to perform rotations, and that's just about all you'll find yourself caring about in graphics. Now, let's say we want to rotate this polygon by 90 degrees about the x axis. We just figure out the matrix which represents this operation...
    Code:
    ( 1,  0,  0)
    ( 0,  0, -1)
    ( 0,  1,  0)
    We multiply the matrix representing the operation by the one representing the polygon, and viola, we have a new set of vectors representing the original polygon rotated by 90 degrees.

    There are some properties affecting vectors as matrices. First off, for every vector that goes into the equation, a vector will come out. The dimension of the vectors may change, for example, we might pass 3 dimensional vectors to be operated on, and come out with 4 dimensional, or even 1 dimensional vectors, but the number of vectors will not change.
    Second, when we run together the vectors like this, the vectors don't affect each other. The only reason we clump them together for matrix multiplication is that since we're usually performing the same operation on all the vectors representing a polygon, it's efficient to just perform all the operations at once.
    Last edited by QuestionC; 01-03-2002 at 03:26 AM.
    Callou collei we'll code the way
    Of prime numbers and pings!

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    47
    yep, that's what I needed to know. Thanks a lot. One more question about a code example.


    for (xIdx = 0; xIdx < 36; xIdx++) // x-direction
    { for (yIdx = 0; yIdx < 18; yIdx++) // y-direction
    { // calculate texture coordinates for current quad
    texLeft = float(xIdx) / 35.0f; // left texture coordinate
    texBottom = float(yIdx) / 18.0f; // bottom texture
    coordinate texRight = float(xIdx+1) / 35.0f; // right texture coordinate
    texTop = float(yIdx+1) / 18.0f; // top texture coordinate


    Can someone tell me why they are dividing by 35 and 18 here? This is a 36x20 field of points.
    Last edited by subnet_rx; 01-03-2002 at 10:36 AM.

  4. #4
    Registered User Coder's Avatar
    Join Date
    Aug 2001
    Location
    Cairo, Egypt
    Posts
    128
    for (xIdx = 0; xIdx < 36; xIdx++) // x-direction
    { for (yIdx = 0; yIdx < 18; yIdx++) // y-direction
    { // calculate texture coordinates for current quad
    texLeft = float(xIdx) / 35.0f; // left texture coordinate
    texBottom = float(yIdx) / 18.0f; // bottom texture
    coordinate texRight = float(xIdx+1) / 35.0f; // right texture coordinate
    texTop = float(yIdx+1) / 18.0f; // top texture coordinate
    When :
    0 == xldx : texLeft = 0
    35== xldx : texLeft = 1
    texRight is texLeft + 1/35 always
    0 == yldx :texBottom = 0
    17 == yldx: texBottom = 1
    textTop is textBottom + 1/18 always

    The texture coordinates for many systems are taken in the range of 0 - 1, the guy adjusted the code to achieve that. (Although it range from 0 - 1 1/35 & 0 - 1 1/18 here)

    =====================================
    Intro to 3D graphics programming articles I - V (1 - 5) :http://www.gamedev.net/reference/art...article795.asp
    Matrix & Quaternion Faq : http://skal.planet-d.net/demo/matrixfaq.htm

    //Matrix here...
    ( 2, -2, 1, 3)
    ( 3, 5, -4, 4)
    (-5, 6, 4, 5)
    // Each column is a vector, read from top to bottom
    This is the column major mode I guess.
    Everyone (except GL) I've seen uses the other mode where :
    Code:
    (x , y , z , w) // Unit Vector of X axis
    (x , y , z , w)// Unit vector of Y axis
    (x , y , z , w)// Unit vector of Z axis
    (x , y , z , w)// Origin of coordinate system
    When you mutliply a vector by a matrix, you just modify the vector's coordinates from the ordinary coordinate system to the coordinate system defined by the matrix' axis

    Here is a rotation by 90 degree around Y axis matrix (Z increases into the screen, Y increases upwards, X increases to the right : i.e A left hand system)
    Code:
    (  0 , 0 , 1 , 0)  // X axis now points into the screen
    (  0 , 1 , 0 , 0) // Y axis unmodified
    ( -1, 0 , 0 , 0 )// Z axis points to the left (-ve old X)
    (  0 , 0 , 0 ,1)// Origin is as is
    Translation matrices are obtained by simply using the x,y,z values of the origin as tx,ty,tz (translation)

    Paul nettle has made some nice explanation of matrices at : http://www.flipcode.com/cgi-bin/msg....m=askmid&id=-1
    He did it in his Ask midnight column on flipcode.com
    Muhammad Haggag

  5. #5
    Registered User Coder's Avatar
    Join Date
    Aug 2001
    Location
    Cairo, Egypt
    Posts
    128
    3DICA22 : http://www.programmersheaven.com/sea...sp?FileID=6223

    This is the best 3D mathematics & graphics tutorial I've seen. It'll explain the vectors, matrices as well as some other subjects - although not in complete detail - enough to get you started.

    Don't forget to visit www.gamedev.net , look at their articles sections : Graphics & Math
    Muhammad Haggag

  6. #6
    Registered User
    Join Date
    Dec 2001
    Posts
    47
    yeah, I found one very good article on one guys view of matrices, and it told me a lot. My biggest problem is seeing the big picture. I can look at each piece of code and see what it is doing, but when I picture the entire process in my mind, I lose track. Thanks for the great explanations.

  7. #7
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    A point is a vector.
    Here is an online linear algebra textbook.
    http://www.math.unl.edu/~tshores/linalgtext.html

    You should be able to make your way through most
    of it without calculus.

  8. #8
    Registered User
    Join Date
    Dec 2001
    Posts
    47
    It may actually be different in linear algebra, but in 3D, a point isn't a vector. A vector is the displacement between two points and unlike a point, does not have a fixed position in space. Although, you cannot tell them apart unless you start dealing with a fourth component of a vector, called a homogeneous coordinate.

    Umm, how'd I do? Am I learning?

  9. #9
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    Also in linear algebra a point isn't a vector. A vector has size and direction. A vector may be rotated in a vector-space. The way you can move the vector depends on the dimension of the space (1D, 2D, 3D, 4D etc.).

  10. #10
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    A vector is basically for most purposes is just a list of numbers.

    Talking about a displacement vector d means admitting that a point is a vector.

    p' = d + p
    Which is vector addition.
    The magnitute and direction you can find by converting the point into polar coordinates.
    I was first tought how to add vectors by adding simple position vectors on paper.

    The book on the internet isn't as easy to read as the one I have in print but you can read the section about spanning sets, vector spaces, bases and dimensions.

  11. #11
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    Also another common use for vectors is the coefficents of a linear equation. Talking about
    magnitudes and direction here would be meaningless but you still can find a magnitute and direction.

  12. #12
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    Umm, how'd I do? Am I learning?
    You seem to know more about it than me already, so feel good . Sorry about things I might have gotten wrong, I only really know linear algebra, but it isn't really that big a jump to see how you can do the same with 3d objects.
    Callou collei we'll code the way
    Of prime numbers and pings!

  13. #13
    Registered User
    Join Date
    Dec 2001
    Posts
    47
    Originally posted by QuestionC
    You seem to know more about it than me already, so feel good .
    I really doubt that. I am now studying cos, sin, and tan. I already knew about them, but I have no idea why they are used in 3D. Someone told me they are used with camera angles and viewpoint matrices. Which is basically inline with the code. But I'm still having trouble knowing which one to use when. So, in short, your still WAY ahead.

  14. #14
    Unregistered
    Guest
    Point really isn't a vector. Not even in linear algebra. The vector as it's usually used in 3D graphics isn't the same as vector in linear algebra, but it's a "free vector" as we call it in Czech, because you can place it anywhere and it doesn't change its coordinates. Point is an abstract entity built over a 3D vector space.

  15. #15
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    But when you say 3D vector space your talking
    about a set of vectors (or in this case points)
    {span ((1, 0, 0), (0, 1, 0), (0, 0, 1)) }

    Ok I give up. A point isn't vector but a point
    can be represented as a vector.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help it won't compile!!!!!
    By esbo in forum C Programming
    Replies: 58
    Last Post: 01-04-2009, 03:22 PM
  2. Replies: 8
    Last Post: 11-03-2008, 09:48 PM
  3. Vectors
    By naseerhaider in forum C++ Programming
    Replies: 11
    Last Post: 05-09-2008, 09:21 AM
  4. Yahtzee C++ programme help
    By kenneth_888 in forum C++ Programming
    Replies: 13
    Last Post: 09-05-2007, 03:14 PM
  5. CProg Fantasy Football version pi
    By Govtcheez in forum A Brief History of Cprogramming.com
    Replies: 155
    Last Post: 12-26-2006, 04:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21