Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Tagged as

3D Game Math Primer 3: What Are Vectors Anyway?

, 10 Dec 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
Well what are vectors anyway? The topic of vectors crop up in geometry, physics, engineering disciplines, mechanics, etc. How they are used, as well as their definitions at times, vary from context to context. Below I have listed how vectors are defined in some contexts: 1. In geometry, Euclidian (o

Well what are vectors anyway? The topic of vectors crop up in geometry, physics, engineering disciplines, mechanics, etc. How they are used, as well as their definitions at times, vary from context to context. Below I have listed how vectors are defined in some contexts:

  1. In geometry, Euclidian (or spatial) vectors are line segments that represent length and direction.
  2. In physics, vectors are used to show magnitude (usually in some unit) and direction, representing aspects such as velocity, force etc.
  3. In linear algebra, vectors are elements of vector spaces, but unlike the above attributes of vectors, may not always be made up of real numbers.

I liken vectors to cross-cutting concerns in regular software applications. One example of a cross cutting concern in software applications is logging. In any one of the layers in a layered software architecture, logging is an important function that is applied across the layers (or used as an aspect, in Aspect Oriented Programming lingo).

Vectors are a cross-cutting concern across geometry, linear algebra, mechanics, engineering, fluid dynamics, etc. Vectors are a necessary and critical element in each of these areas, but is pretty much the same thing when taken by itself, and can be treated as an aspect, if I may use the term again from AOP.

Lets backtrack for a moment: A geometrical point is something and nothing at the same time. It is purely a location in space, but has no width, height, length, or any type of dimensional size. Next, a line can be defined as the straight path between two points. But can this straight path have any thickness or size? Points and lines are abstract idealizations in geometry, we cannot create or draw them, but we can visualize them by giving them size, thickness etc, that will make sense to our eyes as points and lines. A vector is yet another abstraction, which represents the magnitude of something (denoted by the length of  a directional line segment), and the direction of the acting element to which the magnitude is applicable. A vector starts from a initial point, and ends at a terminal point, with the directed line segment connecting the two points representing the magnitude and direction.

What game programmers need to know is that vectors can be represented as lists of numbers (or arrays, to be more accurate). If the initial point of each vector is taken as the origin of a coordinate system, every vector can be represented by a list of numbers. In two dimension, vectors can exist only on a plane, and thus need a minimum of two numbers (or values) to be defined in a list. In 3D, vectors can exist in 3D space, and need a minimum of three numbers to be defined. But it can be more than three dimensions, and we will see about higher dimension vectors in a future post, which has further implications in 3D game programming.

One important consideration when talking about vectors, is the relationship they have to points. Points were explained to represent only position. Vectors do not have position, but have magnitude and directions (displacement). But points do not have precise or absolute locations, their locations are defined relative to some coordinate space. Now, what happens when you draw a line segment from the origin of this coordinate space to the point in question? What we get is the displacement of that point, from the origin. Thus, in a given coordinate system, if we have a vector starting from the origin and describing a displacement of [x, y], we end up in the location of the point represented by [x, y]. What we need to remember is that points and vectors are conceptually (think physics) different but mathematically (think geometry) equivalent.

To sum up, vectors are simply directional line segments that represent a certain direction, and a magnitude which is denoted by the length of the line. If the vector is initiated from the origin of a coordinate system, the vector is equivalent to a point in the coordinate space whose coordinates are the same as for the vectors terminal point (And vice-versa: The displacement of a point in a coordinate space from the origin, is given by the vector that begins from the origin and ends at the point).

In the next post, we will look at where vectors are used in 3D games development, and some of the basic vector operations that we need to know about.


License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Mark Sinnathamby
Software Developer Air Liquide Industrial Services
Singapore Singapore
Mark is a software developer at Air Liquide Industrial Services - Singapore, where he helps Develop, Deploy, and Maintain large scale enterprise applications in the Asia-Pacific region. While his main work experience converges on .Net technologies, he has proficient experience in C++, HTML5/CSS/Javascript Web technologies, mobile development, OpenGL and DirectX API's, as well as a bit of J2EE. He loves to dabble with Game programming in his spare time, and blogs about his development experience at http://markfaction.wordpress.com and http://gamecoderlogic.wordpress.com.
Follow on   Twitter

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141220.1 | Last Updated 10 Dec 2012
Article Copyright 2012 by Mark Sinnathamby
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid