View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Pratical Usage of Vector Spaces in Programming or game programming

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

7 replies to this topic

### #1warnexus  Prime Members

Posted 27 September 2013 - 07:52 AM

I am trying to grasp the idea of vector spaces in my linear algebra textbook. The only thing I got out of it was that a vector space is set of elements or vectors (elements and vectors seems to be used interchangably which causes confusion) that must satisfies 10 rules that involves matrix addition and scalar multiplication in order to be called a vector space.

This concept is a whole lot more abstract compared to what was covered before: which was on system of linear equations and echileon forms.

Question: I still do not see the big picture or the whole point of learning vector spaces. I am trying to find the motivation to appreciate vector spaces. It has been 2 days and it is still an abstract concept to understand fully. Am I approaching vector spaces the wrong way?

Edited by warnexus, 27 September 2013 - 08:01 AM.

### #2Álvaro  Members

Posted 27 September 2013 - 08:42 AM

The point of introducing vector spaces axiomatically (the 10 rules are called "axioms") is that you can recognize them in many situations, and then a lot of the knowledge you have will apply. The short version of the formal definition is that a vector space is a set of things that can be added, multiplied [EDIT: subtracted] and scaled (i.e., multiplied by number).

Besides R^n as a vector space over the reals, there are many other things that are vector spaces:
* Matrices
* Polynomials of degree 3
* Polynomials
* Sequences of real numbers
* Functions from reals to reals
* Continuous functions from reals to reals
* Complex numbers (they are a 2-dimensional vector space over the reals)
* Quaternions (they are a 4-dimensional vector space over the reals)
* unsigned integers, considering XOR as the addition (you can think of them as a 32-dimensional vector space over the field of two elements)

There will be situations where you will find a vector space while solving a problem, and I give you an example below. But before I lose you in the details of a complicated problem, let me say that the most important benefit of learning about vector spaces, like most of math, is that it will train you to look at problems in new ways.

And now the example. Let's try to find a closed formula for the Fibonacci sequence. That is, we want to find a formula F[n] such that

F[0] = 0, F[1] =1, F[n+2] = F[n+1]+F[n]

Ignore for a second the first two conditions and concentrate on the last one. The set of sequences that satisfy that equation is a vector space, because the sum of two sequences that satisfy that equation satisfies that equation and scaling a sequence that satisfies the equation also satisfies the equation. As an exercise, you should check that all the axioms are satisfied.

Once you learn a bit more from you book, you'll be able to determine that this vector space has dimension two (because the sequence that starts A[0]=1, A[1]=0 and the sequence with B[0]=0, B[1]=1 are linearly independent and can generate any member of the vector space), so all you have to do is find two linearly-independent formulas that satisfy F[n+2] = F[n+1]+F[n] and you know that you can find the formula for Fibonacci as a linear combination of the two. These two formulas are geometric series of the form

F[n] = x^n

In order to find appropriate values for x, write F[n+2] = F[n+1]+F[n], which is x^(n+2) = x^(n+1)+x^n, and after dividing by x^n you get

x^2 = x+1

Solve this second degree equation, find the two values of x that make the formula work and then figure out the coefficients that you have to use to combine the two geometric sequences (Impose F[0]=0 and F[1]=1 and you'll get a system of 2 equations with 2 unknowns which is easy to solve).

Edited by Álvaro, 27 September 2013 - 11:26 AM.

### #3Paradigm Shifter  Members

Posted 27 September 2013 - 09:34 AM

Matrices and quaternions aren't very good examples of vector spaces since there aren't any rules to multiply elements together in vector space, which is the thing you usually do with matrices and quaternions. They are good examples of (non-commutative) rings though.

The short version of the formal definition is that a vector space is a set of things that can be added, multiplied and scaled (i.e., multiplied by number).

Are you sure you are thinking of a vector space? Vector spaces don't define multiplication between elements, only addition of vectors and multiplication by a scalar. I think you are thinking of a ring.

EDIT: Inner product spaces, which are a further refinement of vector spaces, define the inner product which acts on 2 vectors but that results in a scalar not a vector (the dot product Rn . Rn -> R is an example of an inner product).

Edited by Paradigm Shifter, 27 September 2013 - 09:41 AM.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

### #4LorenzoGatti  Members

Posted 27 September 2013 - 09:38 AM

Some typical patterns of "intelligent" linear algebra applications:

- Recognize that a set of things has to be linearly independent, or they behave badly. How do you verify they are independent? Which vector space do these things belong to? Only a number of things equal to the dimension of the space can be linearly independent, if you want more you need to upgrade to a different vector space.

- Similar to the above: recognize that the constraints on something form a system of linear equations, eliminate linearly dependent equations that don't actually add constraints, and figure out whether (and/or in which situations) the complete system is underdetermined, solvable or overdetermined. Which of the three cases are possible? Can you deal with them, or you need to rethink the whole system?

- When there are multiple vector spaces, one might be a subspace of the other, or each might be a different extension of a common subspace, or they can be unrelated. Which isomorphisms and projections make sense? Can you treat these spaces uniformly in your code?

Omae Wa Mou Shindeiru

### #5Álvaro  Members

Posted 27 September 2013 - 11:25 AM

Matrices and quaternions aren't very good examples of vector spaces since there aren't any rules to multiply elements together in vector space, which is the thing you usually do with matrices and quaternions. They are good examples of (non-commutative) rings though.

Yes, they are non-commutative rings, but they are also vector spaces, and sometimes it's a good idea to think about them that way. By the way, they are also Lie groups. There are many ways to look at the same object. Sometimes you may want to think of the reals as a vector space over the rationals.

The short version of the formal definition is that a vector space is a set of things that can be added, multiplied and scaled (i.e., multiplied by number).

Are you sure you are thinking of a vector space? Vector spaces don't define multiplication between elements, only addition of vectors and multiplication by a scalar. I think you are thinking of a ring.

Oh, damn it. I meant to say "subtracted", not "multiplied". Sorry about that.

Edited by Álvaro, 27 September 2013 - 11:26 AM.

### #6Norman Barrows  Members

Posted 28 September 2013 - 07:44 AM

linear algebra and analytic geometry are the two primary math disciplines in 3d graphics.

learn it, know it, live it, breathe it, dream it.

i got an A in linear at OSU and still wish i knew the subject better.

and i've been doing 3d game graphics for a quarter of a century!

vector spaces and spanning sets and such are the more theoretical side.   later you'll get into applications  where being able to recognize these situations and applying the theory are the key to solving the problem.  IE because of <some condition> we know this is a <vector space | spanning set | linearly independent, | etc > situation and we can apply rule (axiom) <some rule> to solve the problem.

later in making games, it can help with more elegant solutions to uncommon tasks.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

### #7JohnnyCode  Members

Posted 30 September 2013 - 08:38 AM

beside the axioms a set must prove to be a vector space, there are a few short cuts to explain vectors space(s). A vector can exist in any amount of vector spaces, so to keep its identity, it is expressed in every vector space differently depending on the vector space's basis vectors. Little ToDo for you:

vector (2,1,4) in a vector space H defined by basis vectors (1,0,0)x(0,1,0)x(0,0,1) over R(eal numbers) is expressed as (1,0.5,2) in vector space G over R(eal numbers), Find the basis vectors of vector space G. Define the matrix that transforms from vector space G to vector space H.

if you solve this, you will have a little decent understanding of vector space(s).

### #8Álvaro  Members

Posted 30 September 2013 - 11:51 AM

JohnnyCode's language is non-standard. I think what he means to say is that a vector can be expressed using coordinates, but the coordinates depend on the basis we are using.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.