# Change of basis

This topic is 3900 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

If I'm building a new orthonormal basis for some new space FooSpace, does this basis transform objects from (say) world space into FooSpace, or does the basis go from FooSpace to world space? Pseudo shader code e.g:
matFooSpace = [ F0x F1x F2x
F0y F1y F2y
F0z F1z F2z ] (where F0-2 are the basis vectors)

// Which is right:
float3 myVectorInFooSpace = mul(matFooSpace, myVectorInWorldSpace);
float3 myVectorInFooSpace = mul(transpose(matFooSpace), myVectorInWorldSpace);



##### Share on other sites
The basis vectors for FooSpace, F0*, are represented in world space, so (F0x, F0y, F0z) is the direction that Foo's x axis points in world space.

So, assuming mul() operates in the way traditional matrix math is written on paper, you want the second line of code, e.g., what you want is:

world to Foo:    [F0x F0y F0z] [Wx]R = |F1x F1y F1z| |Wy]    [F2x F2y F2z] [Wz]

This way, if you have W = (1,0,0), it maps to (F0x, F1x, F2x) in FooSpace. And doing the reverse, you expect (F0x, F1x, F2x) to map back to (1,0,0):

Foo to world    [F0x F1x F2x] [F0x]R = |F0y F1y F2y| |F1x]    [F0z F1z F2z] [F2x]

Since F0* are unit length vectors and since its an orthonormal basis, this regenerates the proper world space vector (1,0,0), proving that the world to Foo transformation (and vice versa) worked correctly.

[Edited by - grhodes_at_work on February 13, 2008 1:45:54 AM]

##### Share on other sites
Quote:
 Original post by grhodes_at_workThe basis vectors for FooSpace, F0*, are represented in world space, so (F0x, F0y, F0z) is the direction that Foo's x axis points in world space.

How should I think about transformations that don't necessarily take place from world space? For example, a tangent-binormal-normal matrix for normal mapping - this matrix goes from object space to tangent space. Or a light space matrix that goes from camera space to light space (i.e. transforming an object into the point of view of the light).

If I build my tangent basis as follows, how do I know which direction the transformation will go in? I'm guessing object to tangent, but I don't have an intuitive feel.

// Go from object space to tangent spacematTBN = [ Tx  Ty  Tz            Bx  By  Bz            Nx  Ny  Nz ]// Go from camera space to light spacematLight = [ L0x  L0y  L0z             L1x  L1y  L1z             L2x  L2y  L2z ]

Thanks!

##### Share on other sites
The basis vectors inside your transformation matrix are defined with respect to some other coordinate system. If the basis vectors are "in" canonical world space, then they're defined with respect to the canonical world space vectors (1,0,0), (0,1,0), and (0,0,1). This means that you're either transforming to or from canonical world space, depending on whether the basis vectors are in the rows or columns. The space defined by the actual basis vectors is the second space (that you're transforming to or from).

In many cases, the basic vectors are defined with respect to some other coordinate system. This space, the one in which the basis vectors is defined, is one source/destination -- call it 'A'. The space defined by the basis vectors themselves, is the other source/destination -- call it 'B'. Take view space. The basis vectors are often defined with respect to world-space (often canonical world-space), and the basis vectors themselves are view-space. Hence this transformation can take you between world-space and view-space. If this is a bit confusing at first, just remember that while basis vectors define a space themselves, they also need to be inside another space. It's recursive in nature.

For column vectors (matrix-vector multiplication order), if the basis vectors are in the columns of the matrix, you're going from space B to space A. If the basis vectors are in the rows of the matrix, you're going from space A to space B. For row vectors (vector-matrix multiplication order), if the basis vectors are in the columns you're going from space A to space B. If the basis vectors are in the rows you're going from space B to space A. Take note of the symmetry between row/column vectors, and putting the basis vectors in the rows or columns of the matrix.

Ultimately, when you perform the matrix operation, one of two things is going to happen. The point you're transforming is going to be "dotted" (i.e. have the dot product taken with) with the basis vectors, or it's going to linearly combine the basis vectors. In the former case, you're going from space A to space B. In the latter case, you're going from space B to space A. This way of seeing things in convention-independent, which is why I prefer it.

That wasn't the most technical of explanations, but just some tricks and mnemonics I've found useful over the years.

1. 1
2. 2
Rutin
25
3. 3
4. 4
5. 5

• 9
• 13
• 19
• 14
• 9
• ### Forum Statistics

• Total Topics
632940
• Total Posts
3009327
• ### Who's Online (See full list)

There are no registered users currently online

×