What Are Vectors
What a Vector Is
Vector is an overloaded word, context determines its meaning.
In mathematics, a vector tells us how far to go in a certain direction.
A vector has two parts, a length (or magnitude) and a direction.
A vector instructs us to go its length in its direction.
Vectors are simple.
What a Vector Is Not
- Tell us where something is
- Change when we move them (when graphing)
this allows us to visualize the dot product.
How to Think of Vectors
We think of vectors as instructions for movement.
Let's do an experiment.
Let's consider these instructions:
Take 3 steps to the right and then 2 steps forward.
Our instructions could be described as the Cartesian vector <3, 2>. We could describe it as a Polar vector, but in this experiment Cartesian is easier to use If we apply our vector (we follow the instructions) we would change our positions; we would end at a different position because we started at different positions. We can apply our vector as many times as we'd like to further change our position. Vectors don't know or care where the thing that is being moved ends up
Cartesian vectors are composed of an x and y.
Cartesian vectors look like this
vector v = (6, 4); //or
vector v = <6, 4>;
// you might also see the numbers vertically stacked between [ ]
// we may see a 3D vector with a z component <6, 4, 7>
The first number represents horizontal movement, the second represents vertical movement.
This tells us to move 6 steps horizontally and 4 steps vertically.
Where are the length and direction?
They are baked in.
We can calculate the length, if needed, by using the distance formula.
We can calculate the direction, if needed, by using trigonometry, for example the atan function.
A Polar vector directly give us a length and direction (angle).
It may look something like this
vector p = (4, 120°); //length is 4 and the angle is 120 degrees
We have some work to figure how far up and over we need to go, but we know that we will be 4 units away from where we started and the angle between the points will be 120 degrees.
We can figure out how far horizontally and vertically we need to go with basic trigonometry.
horizontal_dist = cos(120°) * 4;
vertical_dist = sin(120°) * 4;
Cartesian vs Polar
Should we prefer Cartesian or Polar vectors? Depends.
The question is: how are we going to use the vector?
Sometimes one is more convenient than the other, but in the end, they give us the same information in different ways.
How Are Vectors Used
A few common uses for vectors are:
- Describe an objects movement or potential movement
- Describe which way something is facing (for example a polygon)
- Measure a "force" such as wind
Difference Between a Vector and a Point
Vectors and points look similar, how are they different.
point p = (6, 4); // describes a point in space
Points describe a position (end point), vectors don't describe an end point.
We could apply vector v to point p and p would change to (12, 8).
vector v = <6, 4>; // an instruction to go 6 to the right and 4 up
We could do it again and p would change to (18, 12).
- Elements of Programming
- Beginning Math and Physics for Game Programmers
- Euclid's Elements (The Thirteen Books)
- From Mathematics to Generic Programming
- Data-oriented design: software engineering for limited resources and short schedules
- Design of Design, The: Essays from a Computer Scientist
- Mythical Man-Month, The: Essays on Software Engineering, Anniversary Edition
- More Effective C++: 35 New Ways to Improve Your Programs and Designs
- Mathematics for Machine Learning
- The Pragmatic Programmer: Your Journey To Mastery, 20th Anniversary Edition (2nd Edition)
- Schaum's Outline of Essential Computer Mathematics 1st Edition
- All recommended resources