Vectors or Arrays?

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Vectors or Arrays?

Post by Asimov » July 14th, 2012, 9:16 pm

Hi Chilli,

I have used arrays quite extensivey over the years for different projects, but I just came across this page
http://www.mochima.com/tutorials/vectors.html

It said in C++ they talk about Vectors rather than arrays. Anyway it seems vectors can change size on the fly and have some of the funtionality you put into your score class.

I know they use vectors in 3D.

So what is the difference between a vector and an array?

Asimov
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Vectors or Arrays?

Post by chili » July 15th, 2012, 5:00 am

Asimov wrote:I know they use vectors in 3D.
Okay, before I answer your question, we need to address this. :?
The term 'vector' has different meanings depending on what we're talking about, so we need to be careful about using it.

In mathematics, a vector is something that has magnitude and direction. It is generally represented by a [1 by n] matrix or an [n by 1] matrix (row vector or column vector). However, it need not be represented by a matrix (matrix is basically the mathematical equivalent of an array).

In C++, a vector is an array which can dynamically resize. When we talk about vectors, we usually mean std::vector, which can not only dynamically resize, but also provides facilities such as out of bounds testing.

When using mathematical vectors, we need not use std::vector. In fact, we often won't when we use hardware-accelerated 3D (because of the way direct3D works).

In general, we will be making more use of std::vector in the future because it is easier than managing arrays and it's safer. However, in situations where speed or memory usage are an issue, we will naked arrays (for example, surfaces will always be arrays, never vectors). Also, there are functions that only take naked arrays as parameters, so in those cases too we will be using naked arrays.
Chili

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Vectors or Arrays?

Post by Asimov » July 15th, 2012, 11:10 am

Hi Chill,

Cool I can't wait.

Asimov
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
ocunder
Posts: 11
Joined: July 11th, 2012, 3:19 am

Re: Vectors or Arrays?

Post by ocunder » July 15th, 2012, 11:54 am

what branch are vectors apart of.. ? physics?

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Vectors or Arrays?

Post by chili » July 15th, 2012, 12:24 pm

Vectors are a pure math concept. They see a lot of use in physics calculations.
Chili

Post Reply