Adding Vectors

This is a discussion on Adding Vectors within the Game Programming forums, part of the General Programming Boards category; I guess this is more conceptual, and not very game programming related, but okay. I have a quantity which is ...

  1. #1
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465

    Adding Vectors

    I guess this is more conceptual, and not very game programming related, but okay. I have a quantity which is represented by a unit vector in a cvector class, which has an x, y, z, and magnitude values and then can normalize itself. In my situation they represent acceleration due to gravitation. I don't understand how I can add a vector in the form aB + cD = xY with a, b being scaler magnitudes, B and D being directed unit vectors, and xY being sum.

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  2. #2
    Registered User
    Join Date
    Apr 2004
    Posts
    42
    a<x,y,z> + b<A,B,C> = <ax,ay,az> + <bA,bB,bC> = <ax +bA, ay + bB, az + bC>

    err, is that what you wanted?

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    You need to multiply 2 vectors by 2 sep scalars and then add the results?

    To multiply a vector V by a scalar s:

    V*s=(V.x*s,V.y*s,V.z*s)

    To add two vectors V1 and V2:

    V1+V2=(V1.x+V2.x,V1.y+V2.y,V1.z+V2.z)

  4. #4
    Registered User
    Join Date
    Nov 2006
    Posts
    13
    For the original question I suggest you look for tutorials on operator overloading. Most of them use a vector class to teach you the concept. With this you can specify how the class is manipulated when other data types are used with that operator. If you have a Vector3d vec(1,5,3) and then write vec = vec*5, vec will now be 5,25,15.

    <off topic> Also what were the C++ people thinking when they named a stl linked list type thing "std::vector" that is just confusing.</off topic>
    Last edited by newtocpp; 11-18-2006 at 04:40 AM.

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    We answered the original question.

  6. #6
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Okay.

    So, if I were to be calculating the acceleration of, for example, the acceleration due to gravity of one object to another, would I use the normalized displacement vector of the one object to the other multiplied by the scaler magnitude of the that acceleration?

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How can i made vectors measuring program in DevC++
    By flame82 in forum C Programming
    Replies: 1
    Last Post: 05-07-2008, 02:05 PM
  2. How properly get data out of vectors of templates?
    By 6tr6tr in forum C++ Programming
    Replies: 4
    Last Post: 04-15-2008, 10:35 AM
  3. Adding vectors ??
    By Hussain Hani in forum C++ Programming
    Replies: 1
    Last Post: 11-18-2006, 02:03 AM
  4. SVN Import Causes Crash
    By Tonto in forum Tech Board
    Replies: 6
    Last Post: 11-01-2006, 02:44 PM
  5. adding vectors
    By sdchem in forum C++ Programming
    Replies: 2
    Last Post: 04-22-2003, 11:34 AM

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