Why do they call it Vector?

AS3 has a new type known as Vector, which is essentially a typed array. So you can say:

var myList:Vector.< Point > = new Vector.< Point >();

Now myList functions almost exactly like an array – has most of the same properties and methods as an array, but you can only put Point objects in it. And you can be sure that anything you get out of it is a Point. This allows the compiler to compile much more efficiently and your code to run much faster. All cool.

But I’ve heard a lot of people ask, “Why do they call it a Vector?”

I’ve always just said, well that’s what they call it in other languages, like that is some kind of answer or something. But I finally decided to come up with a real answer.

So Vector means a few different things when you’re doing programming. You have vector graphics, which define lines and curves instead of bitmaps, and you have vectors which define a magnitude in a specific direction. But neither one of those has anything to do with a typed array, do they?

Well, to find the answer, we go into linear algebra and matrices (matrixes if you prefer). So you know what a matrix is maybe. A two (or more) dimensional grid:

Turns out that a vector is a single row or column (one-dimensional) matrix:

See row vector or column vector.

Well, that’s starting to look like an array. But still, why do they call a one-dimensional matrix a vector? Well it does go back to that definition of a magnitude and a direction.

Say you have a vector with a magnitude of 5, and an angle of something around 36.869. The x and y components of that vector would be 4 and 3 (if I got my math right). You could express this vector in a one dimensional matrix like so:

[4, 3]

Similarly, a 3-dimensional vector could be expressed in a matrix:

[x, y, z]

This site helps too:

http://www.kwon3d.com/theory/vectmat.html

So, a one dimensional matrix is a vector. And we borrowed the term in computer science, even though our vectors aren’t always used to hold vectors and have many more elements than most vectors would normally have. That’s the best answer I have. If I’ve screwed up too badly, I know there’s a few smart people who read this blog who will correct me.

This entry was posted in ActionScript, Flash. Bookmark the permalink.

15 Responses to Why do they call it Vector?

  1. Martin says:

    And the best answer I’ve heard so far. I still find the choice of conventional name a tad confusing I mean; Array? Yes! I get it! It’s (as the dictionary would have it) “an ordered arrangement”, whilst “Vector”? Seems very abstract in the context.

    But again; Kudos. It’s just a tad more understandable now.

    -m

  2. TK says:

    I always thought they just named it after a guy named Vector…

  3. Tyler Egeto says:

    I don’t like it mostly because I have classes in packages with the name Vector already, as do many people I am sure. TypedArray would have worked nice, but really, at the end of the day I am just really happy to see this added to the ActionScript language!

  4. eric dolecki says:

    Curious why it isn’t

    var myList:Vector. = new Vector();

    And have it typed with Point without repeating twice?

  5. eric dolecki says:

    var myList:Vector.&ltPoint> = new Vector()

    – sorry, that was parsed out of my comment above.

  6. sakri says:

    I bought this book last summer at the airport : http://www.amazon.com/Mathematical-Ideas-Really-Need-Know/dp/1847240089/ref=sr_1_1

    There’s an entry on Matrices, I thought the intro was well written, and I’ll quote (not from memory 😉 ):

    “Ordinary algebra is the traditional algebra in which symbols such as a,b,c,x and y represent single Numbers. [skip some text]. A critical advantage of matrix algebra is that we can think of vast arrays of numbers, such as a data set in statistics as a single entity. More than this, we can manipulate these blocks of numbers simply and efficiently. If we want to add or multiply together all the numbers in two data sets, each consisting of 1000 numbers, we don’t have to perform 1000 calculations – we just have to perform one (adding or multiplying the two matrices together).”

    I think that should be added to the wikipedia entry 😀

  7. Iain says:

    It’s a bad name because lots of people already have their own Vector class for storing position and velocity etc, with x, y and z properties. Other languages (e.g. C# / XNA) also use the word Vector in this context.

    Instead, they should have called it something like List or ArrayList or TypedArray.

    Still, it’s a nice thing to have in the language.

  8. Why not just using Array as the typed one and using * when you do not want to type it, like most variables? Backwards compatibility?

  9. H says:

    eric,

    Try thinking of it this way…

    var myList:Vector.;

    You are declaring a pointer myList as type Vector.

    myList = new Vector.();

    You then instantiate a Vector. and assign it to myList…

    Also, an axis vector can be used to store a direction. You can get an axis vector by normalizing a coordinate vector. Multiplying axis vectors by a distance (magnitude) will get you from one 3D point to another like multiplying a radius with the cos/sin of an angle can get you from one 2D point to another. Storing the cos/sin of an angle in a 2D vector will give you a normalized 2D vector/axis vector.

    //consider
    var p:Point = new Point(4,3);
    var angle:Number = Math.tan(p.y/p.x);
    var magnitude:Number = Math.sqrt(p.x*p.x+p.y*p.y);
    var normal:Point = new Point(p.x/magnitude, p.y/magnitude);

    //the following is approximately equal since sin/cos are iterative functions
    normal.x == Math.sin(angle)
    normal.y == Math.cos(angle)

  10. H says:

    Sorry, my generics didn’t make it through either :S

  11. Jamie Kosoy says:

    I expected that there would be a rational thought behind naming it a vector.

    The problem I have is that this is COMPUTER logical while HUMAN illogical. Why do we unnecessarily confuse ourselves with semantics based on math when we could simply just rename the term something more human readable. TypedArray would’ve done fine.

    I can’t even wait to store a multidimensional typed array filled with points and then try to animate them some how. Just imagine the bug conversationss! “Wait… the vector’s vector isn’t following the correct vector?” :-\

  12. Rob says:

    What’s your vector Victor?

  13. 5566 says:

    I think why it’s called Vector is because Java call it Vector. http://java.sun.com/j2se/1.4.2/docs/api/java/util/Vector.html

    I feel ActionScript is always trying to be Java. In the future, I won’t be surprised to see they remove Array type and everything becomes something like MovieClip[] mcArr=new MovieClip[100]

  14. Pixelero says:

    Why do they call it Vector?

    It’s called ‘Vector’ because of the Latin verb ‘vehere’ = to carry, the word ‘vehicle’ has the same origin …

  15. kaj says:

    A array is like a tensor. then a rank 0 tensor is a array without indices (just a value). a rank 1 tensor a array with one index, A vector. a rank 2 tensor is a array with 2 indices, A matrix….

Leave a Reply