BIT-101 [2003-2017]

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:

https://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.

« Previous Post
Next Post »