Like Tree1Likes
  • 1 Post By grumpy

Storing position/velocity of agents -- opinions wanted

This is a discussion on Storing position/velocity of agents -- opinions wanted within the C++ Programming forums, part of the General Programming Boards category; Hi, I have to do some 2D and 3D agent-based-models, need to track position/velocity of agents. In the past I ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    83

    Storing position/velocity of agents -- opinions wanted

    Hi,

    I have to do some 2D and 3D agent-based-models, need to track position/velocity of agents. In the past I had used some vector and agent classes I had written myself. Lately, I find the vector class cumbersome and have become more acquainted with std::vector.

    I figure I could do the simulations I have to do by just adjusting my agent class to use std::vector -- I don't think I can outdo STL code. Any thoughts? Is there any hypothetical benefit to keeping custom vector classes anymore? I need them only to track floating-point co-ordinates in 2 or 3-space.

    EDIT: The reason I made vector classes in the first place was during my first learning stages with c++. I haven't done agent-based simulations in a while, and so I am looking at my old code and would like to improve it. If anyone with graphics programming experience can weigh in on the most efficient way to store position, velocity of agents which you have to animate in openGL.
    Last edited by Ocifer; 02-02-2012 at 11:08 AM.
    W7, Ubuntu -- mingw, gcc, g++, code::blocks, emacs, notepad++

  2. #2
    msh
    msh is offline
    Novice
    Join Date
    Jul 2009
    Posts
    568
    Keep using your custom vector class. `std::vector` is a storage container, not a mathematical object.
    Disclaimer: This post shows my ignorance at the time of its making. I claim ownership of but not responsibility for all errors in it. Reference at your own peril.

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    83
    Oh, do you mean that I can't think of them as Euclidean vectors and do +, -, * with them? Yeah, if I have to write new math functions to for the std::vectors it does seem to defeat the point.

    Out of curiosity, what is the motivation for calling these STL containers "vectors"?
    Last edited by Ocifer; 02-02-2012 at 12:29 PM.
    W7, Ubuntu -- mingw, gcc, g++, code::blocks, emacs, notepad++

  4. #4
    msh
    msh is offline
    Novice
    Join Date
    Jul 2009
    Posts
    568
    Quote Originally Posted by Ocifer View Post
    Oh, do you mean that I can't think of them as Euclidean vectors and do +, -, * with them? Yeah, if I have to write new math functions to for the std::vectors it does seem to defeat the point.
    That's exactly what I mean.

    Quote Originally Posted by Ocifer View Post
    Out of curiosity, what is the motivation for calling these STL containers "vectors"?
    I honestly have no idea.
    Disclaimer: This post shows my ignorance at the time of its making. I claim ownership of but not responsibility for all errors in it. Reference at your own peril.

  5. #5
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,274
    Quote Originally Posted by Ocifer View Post
    Out of curiosity, what is the motivation for calling these STL containers "vectors"?
    I imagine the name std::array was considered, but rejected because "array" implies certain things, like linear arrangement in memory, which are not actually guaranteed by the container. Actually, I think it was a stupid choice.

    Also, your attempts to simultaneously store position and velocity will be defeated... By Werner Heisenberg.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,313
    Quote Originally Posted by brewbuck
    I imagine the name std::array was considered, but rejected because "array" implies certain things, like linear arrangement in memory, which are not actually guaranteed by the container.
    I had the impression that the lack of a C++98 guarantee that std::vector's elements will be contiguous in memory was a defect from the start rather than something deliberate that was changed in C++03. Maybe if they had come up with the new std::array earlier, they would have chosen std::dynamic_array instead, heh.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,528
    Out of curiosity, what is the motivation for calling these STL containers "vectors"?
    Well, a group of similar things, that can change in size, does look like a mathematical vector.
    (I am referring the "can change in size" from my limited knowledge in linear algebra.. I may be somewhat wrong.)
    Manasij Mukherjee | gcc-4.9.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  8. #8
    Registered User
    Join Date
    Apr 2010
    Posts
    83
    Yeah, I guess if you think about it REALLY in the abstract, a vector is just an ordered set of data (thinking back to Linear Algebra when my professor would often switch from using the vernacular "list of basis elements" to "basis vector" when he mathematized his vernacular English). Weird, that word still has a lot of baggage. I just ASSumed it meant Euclidean vector. Anyway, thanks, guys.
    W7, Ubuntu -- mingw, gcc, g++, code::blocks, emacs, notepad++

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,033
    Quote Originally Posted by manasij7479 View Post
    Well, a group of similar things, that can change in size, does look like a mathematical vector.
    (I am referring the "can change in size" from my limited knowledge in linear algebra.. I may be somewhat wrong.)
    o_O
    A mathematical vector can't change size. It is always a fixed size, but you can naturally "make" an infinitely long vector.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Registered User
    Join Date
    Jun 2005
    Posts
    6,679
    Quote Originally Posted by Ocifer View Post
    Out of curiosity, what is the motivation for calling these STL containers "vectors"?
    Historically, arrays were used in Algol to represent vectors, and the terms were used interchangeably - albeit imprecisely. Algol is one of those languages that influenced the nomenclature of computer science, and is also a precursor of most modern programming languages including C and C++.

    Mathematically, a vector is defined as a "collection of similar objects that may be manipulated and characterised collectively using a set of defined rules".

    The "Euclidean vector" you are using is a special case of that. For example, the x, y, z in a 3D euclidean vector are the "similar objects", there are defined rules for addition, dot product, cross product, etc, and the vector has characteristics (properties like length) that are not owned by its elements.
    msh likes this.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Sunshine, and read this, this, and this before posting again.

  11. #11
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,274
    A (mathematical) vector is just something that obeys certain linearity conditions which are expressed in terms of addition and scalar multiplication. Anything that adheres to those rules can be a vector. That includes scalar values, matrices, infinite arrays of things, anything that has a well-defined addition and scalar multiplication along with the aforementioned linearity conditions.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  12. #12
    Registered User
    Join Date
    Jun 2005
    Posts
    6,679
    You're thinking of the concept from linear algebra called a "vector space" (or sometimes "linear space"), brewbuck.

    Vectors are also used in non-linear algebra which, by definition, is not concerned with linear spaces (except maybe as a special case). For example, the coefficients of a polynomial are often represented using vectors, but operations on polynomials are nonlinear (they don't satisfy properties of additivity or homogeneity).
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Sunshine, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Expert opinions wanted!
    By MK27 in forum Linux Programming
    Replies: 8
    Last Post: 11-01-2011, 11:14 AM
  2. Velocity of an object
    By hdragon in forum Game Programming
    Replies: 1
    Last Post: 03-16-2006, 01:35 PM
  3. Programming Microsoft Agents
    By Fizzer in forum Windows Programming
    Replies: 5
    Last Post: 08-31-2003, 07:38 PM
  4. Opinions Wanted
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 03-04-2002, 09:56 AM

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