Vectors - Geometry

Vectors (in the geometrical sense) represent a direction and magnitude (force) in space. Vectors are often drawn as arrows from the origin (0,0) on a graph. The length of the vector is the magnitude and the "direction" of the vector is the direction. Vectors, in 2D, have two values, X and Y. For example, a vector representing the direction 45 degrees from the origin, could have an X value of 1 and a Y value of 1. Combined these "show" the direction of the vector.

Geometric Vectors

Points are positions in space. They have an X value and a Y value (in 2d).

Vectors are geometric/mathematical entities. (In 2d) they simply state the distance traveled in the X direction along with the distance traveled in the Y direction.

Vectors are generally written as pairs of numbers in parentheses such as (5,6), where the 5 is the X value and 6 is the Y value. In computer programming we will often create an x part of the X value, and a y part for the Y value, thus, if the previous vector had a name (say "jims_speed") we would write the vector in a computer program as "jims_speed.x" and "jims_speed.y".

Vectors are often used to represent the direction and speed that someone is traveling. Thus if your vector is 2,2, this means that you are traveling (on the standard X,Y math grid) toward the upper right at a speed of 2.8.

The "speed" of a vector is known as the magnitude and can be computed using the standard Pythagorean formula for finding the length of the hypotenuse of a triangle, Sqrt(X^2 + Y^2).

Vector Operations

Vectors have nice properties just like regular numbers.

  1. Vector Addition

    You can add two vectors together to get the point that you would reach if you followed the first vector and then followed the second vector. This of this as if someone say to walk 10 feet in one direction followed by 5 feet in another. The place you end up at is the sum of these two "vectors".

    Mathematically, the sum of two vectors is equal to the sum of their X parts and then their Y parts.

    Think about if you walk ten feet in one direction and then walk 5 feet in another direction. The sum of your two moves is the vector as if you had simply walked directly to your current spot directly ("on an angle").

    Mathematically, we can show this addition as the following two steps. Consider we have two vectors v1 and v2, the sum of the vectors would be:

    	    
    	    new_vector.x = v1.x + v2.x;
    	    new_vector.y = v1.y + v2.y;
    	    
    	  
  2. Scaling

    You can Multiply or SCALE a vector by a number:

    You can multiply a vector by a scaler (a number). Simply multiply the X part and the Y part by the number. This is the same as saying, if you were going to walk 10 feet in one direction, and someone tells you to walk five times that far, then you would walk 50 feet in that direction.

    Again, in programming terms, if we have two vectors v1 and v2, the "scaled vector" would be:

    	    
    	    new_vector.x = v1.x * 5;
    	    new_vector.y = v1.y * 5;
    	    
    	  
  3. Length/Magnitude of a Vector

    You can ask for the length (i.e., the Magnitude):

    We can ask how long a vector is. This is called the magnitude. The magnitude can be computed using the Pythagorean theorem.

    	    
    	    length_of_the_vector = sqrt ( ( v1.x * v1.x ) + ( v1.y * v1.y ) );
    	    
    	  
  4. Point Subtraction

    You can Subtract two points, one from another, and get the "vector" between them.

    If we subtract a point from another point, we get a vector! This vector is exactly the straight line between the two points. The magnitude of this vector is the distance between the two points. The direction of the vector is from the first point to the second point.

    	    
    	    vector_between.x = point_2.x - point_1.x;
    	    vector_between.y = point_2.y - point_1.y;
    	    
    	  
  5. Normalization

    You can Normalize a vector, which is to say scale it to a uniform length of one.

    Sometimes we don't care how long a vector is, just in which direction it points. All vectors (no matter their size) that point in the same direction have the same direction.

    If we divide a vector by its length (magnitude), we get a unit vector (representing just the direction of the vector). A unit vector is called "unit" because its length is exactly 1.

    Remember, all vectors which point in the same direction have the exact same unit vector, regardless of their magnitude.


Back to Topics List