vector addition?

This is a discussion on vector addition? within the C++ Programming forums, part of the General Programming Boards category; can someone help me understand using vector addition how I can add the first term of three terms and keep ...

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    3

    vector addition?

    can someone help me understand using vector addition how I can add the first term of three terms and keep going? here's and example if I didn't explain that too well.

    X1 X2 X3......X100
    +Y1 +Y2...................
    +Z1 +Z2...................
    __________________

    R1 R2.........................

    and it can be less than 100, 100 is a variable but it is the highest the variable can go

  2. #2
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by mattz714 View Post
    can someone help me understand using vector addition how I can add the first term of three terms and keep going? here's and example if I didn't explain that too well.

    X1 X2 X3......X100
    +Y1 +Y2...................
    +Z1 +Z2...................
    __________________

    R1 R2.........................

    and it can be less than 100, 100 is a variable but it is the highest the variable can go
    Erm... A loop, maybe?

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    5
    .
    It might be OK, since this is a 3D vector 'point', to create a vector 'object' first. You can do that using a typedef.
    Code:
    //this defines a struct of type VPOINT
    typedef struct{
              int x;
              int y;
              int z;
    }VPOINT;
    
    //this 'creates' a vector point
    VPOINT p1;
    Now, I'm not sure you actually want to add the three dimensions (x, y, z) of a vector together, it's more likely the case that you want to increment (or decrement) certain of the dimensions of each vector point to achieve a translate, scale or rotate on them in a point-relative way.

    If you use three of these points to define a shape, say a triangle, you can move the triangle from left to right by incrementing their 'x' values by a fixed amount on subsequent iterations of a loop, drawing connecting lines to show the shape each time (clear the screen between each iteration).
    Code:
    typedef struct{
        VPOINT p1;
        VPOINT p2;
        VPOINT p3;
    }TRIANGLE;
    You first have to define each point's position in space relative to each other (normally in Cartesian coordinates, but you can use screen coords as well).

    Changing just the 'y' values will make the triangles go up and down, changing the 'z' values will make the triangles move closer or farther away.

    When you deal with 1000s of triangles, you can build a complex 3D object that you use matrices to manipulate, these let you operate on all the points at once.

    You'll need direct access to your graphics card to handle complex objects, OpenGL can get you started with that.

    You might try the Game Programming sig on this board for more info on this stuff because unlike the -points- I used as examples, -vectors- also have 'direction'. You define them exactly the way I show above but you operate on them as 'vectors' rather than 'points' and use pretty basic trig routines to manipulate them through their various transforms. As those transforms get more complex, you can (as I pointed out) use matrices and matrix multiplication to handle the tough stuff.
    .
    Last edited by morongo; 10-29-2010 at 11:44 PM.

Popular pages Recent additions subscribe to a feed

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