{"revision": {"id": "f3374b7f-2f95-11f1-979c-e86a64d24d78", "node_id": "f336800e-2f95-11f1-910b-e86a64d24d78", "user_id": "edc3f576-2f95-11f1-900f-e86a64d24d78", "author": "foxhop", "data": "Vector Math for Video Games\r\n=============================\r\n\r\nThis document outlines the common vector math formulas and terminology that is used for building 2d games.\r\n\r\nWhen introducing a new concepts such as vectors, real life examples assist in the learning process. A real life example of a vector is an analog clock.  Analog clocks have hands to represent time.  These hands could also represent vectors.  The hands much like vectors have different lengths or magnitudes.  The hands also have different directions just like the vector.\r\n\r\nTerminology\r\n--------------\r\n\r\n**Vector**\r\n  A quantity possessing both magnitude and direction, represented by an arrow the direction of which indicates the direction of the quantity and the length of which is proportional to the magnitude.  We can represent vectors in our games to determine how to move entities in relation to each other.  \r\n\r\n|\r\n\r\n**Magnitude**\r\n  The size, extent, or length of a Vector.  \r\n\r\n|\r\n\r\n**Direction**\r\n  The position or orientation of a vector.  Vectors point into different directions in space.\r\n\r\n\r\n\r\nHow do we use vectors in games?\r\n--------------------------------\r\n\r\nVectors help keep track of space in games.  Vectors are used to move players and projectiles.  Once you learn how to do vector math, teaching the computer how is lots of fun.  Yes, programming is sort of like teaching a computer how to perform an action.\r\n\r\nWhat is a vector?\r\n---------------------\r\n\r\nA vector consists of a point in space.  This document assumes knowledge about coordinates of points (x,y).  \r\n\r\nMath has developed many techniques to help discribe objects in space by using vector techniques.  I'm going to document the vector techniques used when creating 2d games.\r\n\r\nVector Techniques for 2d games\r\n----------------------------------\r\n\r\nIn the following examples we will describe two vectors, v1 and v2.\r\n \r\nVector Addition\r\n``````````````````\r\n\r\nTwo vectors can be added together to form a new vector.  To perform vector addition, add the x and y coordinates.\r\n\r\n**Syntax:**   \r\n\r\n | ( v1.x + v2.x, v1.y + v2.y ) = ( v3.x, v3.y )\r\n  \r\n**Example:**  \r\n\r\n |  v1 = (3,4)\r\n |  v2 = (4,6)\r\n |  v3 = (3+4,4+6) = (7,10)\r\n\r\nVector addition is just addition of coordinate pairs. Simple right?\r\n\r\n\r\n\r\nVector Subtraction\r\n`````````````````````````````\r\n\r\nTwo vectors can be subtracted from each other to form a new vector.  To perform vector subtraction, subtract the x and y coordinates.\r\n\r\n**Syntax**\r\n\r\n | ( v1.x - v2.x, v1.y - v2.y ) = ( v3.x, v3.y )\r\n\r\n**Example**\r\n\r\n | v1 = (4,2)\r\n | v2 = (3,1)\r\n | v3 = (4-3,2-1) = (1,1)\r\n\r\nVector addition is just subtraction of coordinate pairs. Again, simple right?\r\n\r\n\r\n  \r\n\r\n    ", "source_format": "rst", "revision_number": 6, "created": 1295644036000}}