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.
Many a time I’ve heard statements like “Games programming? 3D graphics? that requires an awful lot of maths right? and graduate level math at that…” ….and therein onwards the interest dies off due to the pre-mis-conceptions about the role that mathematics will play in games development.
For a programmer/developer/software engineer, learning the concepts of 3D mathematics needed for developing games is not an impossible task (the math we use in 3D game programming is referred to as ‘3D math’ but is actually a composite collection of topics from different mathematical disciplines as we shall see shortly). Of course, there will be some due inherent complexity, as there should be with good reason, but we tackle complexity everyday in software engineering: software architecture and patterns, databases and database design, mastering specific technologies that we use to build systems with, web site user experience, all bring about their own inherent complexities, but we master them and control them in order to reach our objectives. In that regard, what is so different about 3D mathematics that we cannot master the complexity, understand it, and apply it? That being said, this may be a good time as any to elaborate on what 3D mathematics is made up of.
The math used in the rendering of 3D games is based on a sub-set of topics derived from the mathematical branches of linear algebra, (solid) geometry, real analysis, and higher algebra. In addition, any artificial intelligence used in game logic and physics simulations, employs real world physics and mathematics as well. But we are currently concerned with the mathematics needed for drawing and rendering 3D graphics for games, and that is what we will focus on at the moment, though we will discus all aspects of game programming, including AI, in later topics.
To this end, I will be creating a thread of posts in this blog that deal with 3D math topics in a linearly progressive fashion, including code examples showing their applications where possible. This is in order to show and prove to the reader, that learning 3D mathematics is not the daunting task it is labeled to be, and also to pave the way for the game programming concepts and topics discussed in this blog that rely on mathematics. It is one of the most rewarding experiences, that when you are developing 3D computer games, you actually understand the mathematical concepts and principles behind what you are doing. For at that point, no aspect of the game is out of your control, as you know and understand exactly what is happening under the hood.