Thread: how to represent velocity vector ?

  1. #1
    Registered User
    Join Date
    Jan 2015
    Posts
    36

    Question how to represent velocity vector ?

    Hi,

    I need to understand the proper way to represent vector in C. Can any one give a hint for it.?
    V = ui+vj+wk.

    Thanks in advance
    shiv

  2. #2
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    The i, j, and k parts are unit vectors that depict the direction of each component of the vector.

    Basically, represent a vector in C using a 1 dimensional array. In your case, an array of 3 elements. It's up to you to maintain how to index the components of the vector.

  3. #3
    Registered User
    Join Date
    Jan 2015
    Posts
    36

    Question

    Quote Originally Posted by MutantJohn View Post
    The i, j, and k parts are unit vectors that depict the direction of each component of the vector.

    Basically, represent a vector in C using a 1 dimensional array. In your case, an array of 3 elements. It's up to you to maintain how to index the components of the vector.
    Thanks for the reply

    My case is 3D.. is this correct for 3D vector, V[i][j][k].?

  4. #4
    Registered User
    Join Date
    Mar 2015
    Location
    BE
    Posts
    66
    I don't understand the meaning of presenting and "my case is 3d" ?

    And try to save i, j and k for your loops. Just a convention. Use x, y and z instead.

  5. #5
    Registered User
    Join Date
    Jan 2015
    Posts
    36

    Post

    Quote Originally Posted by Carnotter View Post
    I don't understand the meaning of presenting and "my case is 3d" ?

    And try to save i, j and k for your loops. Just a convention. Use x, y and z instead.
    Thank you for the reply.

    It means velocity is flowing in all three directions... Thank you

    Code:
    for(x=0;x<10;i++)
    {
        for(y=0;y<10;j++)
        {
            for(z=0;z<10;z++)
            {
                printf("%d", v[x][y][z]);
            }
        }
        
    }
    Is this simple code correct for representing a 3D vector?. If it is correct then I will develop the similar code to compute the velocity..

    shiv

  6. #6
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    You don't need a 3D array.

    All vectors are 1 dimensional. Matrices are 2 dimensional.

    a i + b j + c k is represented in vector form as (a, b, c) so all you need is :
    Code:
    #include <stdio.h>
    
    
    enum { x = 0, y = 1, z = 2 };
    
    
    int main(void)
    {
        float v[3] = { 0 };
    
    
        v[x] = 1.23;
        v[y] = 2.56;
        v[z] = 34.0;
    
    
        printf("v = { %f, %f, %f }\n", v[x], v[y], v[z]);
    
    
        return 0;
    }
    All your doing in this case is using a 1D array to store your vector and we use an enumeration for intuitive indexing of the array.

  7. #7
    Registered User
    Join Date
    Jan 2015
    Posts
    36

    Red face

    Quote Originally Posted by MutantJohn View Post
    You don't need a 3D array.

    All vectors are 1 dimensional. Matrices are 2 dimensional.

    a i + b j + c k is represented in vector form as (a, b, c) so all you need is :
    Code:
    #include <stdio.h>
    
    
    enum { x = 0, y = 1, z = 2 };
    
    
    int main(void)
    {
        float v[3] = { 0 };
    
    
        v[x] = 1.23;
        v[y] = 2.56;
        v[z] = 34.0;
    
    
        printf("v = { %f, %f, %f }\n", v[x], v[y], v[z]);
    
    
        return 0;
    }
    All your doing in this case is using a 1D array to store your vector and we use an enumeration for intuitive indexing of the array.
    Thank you so much. you have solved my problem.. Now I can develop my program easily.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 09-22-2013, 07:00 AM
  2. 2D Ball Collision (velocity vector calculation)
    By Syndacate in forum Game Programming
    Replies: 1
    Last Post: 02-20-2012, 10:08 PM
  3. How to represent a map
    By gavra in forum Game Programming
    Replies: 10
    Last Post: 09-12-2011, 04:44 PM
  4. Represent Maze
    By iamnew in forum C++ Programming
    Replies: 37
    Last Post: 04-28-2010, 08:47 PM
  5. Velocity vector troubles
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 01-18-2005, 11:40 AM