# How to ensure affine transformation matrix represents orthogonal vectors

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

## Recommended Posts

I use a 4x4 affine transformation matrix to represent the location and orientation of objects in 3D space.

It's in my best interest to ensure that the x,y,z vectors (columns 1, 2 and 3) are orthogonal to eachother.

I'm wondering what is efficient way to go about ensuring this.

For example, lets say I have the matrix m set to a particular orientation. I want to now change its z vector to another arbitrary vector. But I want to ensure that it remains orthogonal.

Two methods I can think of would be:

1) Use cross products to redefine the other vectors in terms of the recently changed one:

y = z.cross(y).cross.z
x = z.cross(y);

2) Create the rotation matrix that would be needed to bring the z vector to its new orientation, multiply the entire matrix by it, thus rotating the other vectors as well.

The first method seems like it would be much more efficient, but it will always be redefining the unchanged vectors in terms of eachother. The second method would avoid that but is much less efficient.

Are there any other methods of dealing with this?

##### Share on other sites
Why do you want to change one basis vector? If you rotate the object you have to change all of them, i.e., use an actual rotation matrix. If the other two vectors can be chosen arbitrarily, why do you store them anyway?

##### Share on other sites
You can "orthogonalize" a set of Linear independence vectors using this: http://en.wikipedia.org/wiki/Gram%E2%80%93Schmidt_process
It essentially successively eliminates the "non orthogonal" parts of the vectors.

##### Share on other sites
You basically just cross (product) two to create a third, then recross the third with the first (or second) one, and normalize them all.

If you start with only one vector you can cross it with an arbitrary up vector (0,1,0) to produce the third, then recross 1 and 3 to overwrite the up vector. Just make sure the original is not the same as the up vector.

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5

• 10
• 14
• 30
• 13
• 11
• ### Forum Statistics

• Total Topics
631788
• Total Posts
3002356
×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!