Method of transforming 3D vectors with a matrix

Posted by Drew Noakes on Stack Overflow See other posts from Stack Overflow or by Drew Noakes
Published on 2010-05-31T16:03:55Z Indexed on 2010/05/31 16:43 UTC
Read the original article Hit count: 292

I've been doing some reading on transforming Vector3 with matrices, and am tossing up digging deeper into the math and coding this myself versus using existing code. For whatever reason my school curriculum never included matrices, so I'm filling a gap in my knowledge. Thankfully I only need a few simple things, I think.

Context is that I'm programming a robot for the RoboCup 3D league. I'm coding it in C# but it'll have to run on Mono. Ideally I wouldn't use any existing graphics libraries for this (WinForms/WPF/XNA) as all I really need is a neat subset of matrix transformations.

Specifically, I need translation and x/y/z rotations, and a way of combining multiple transformations into a single matrix. This will then be applied to my own Vector3 type to produce the transformed Vector3.

I've read different advice about this. For example, some model the transformation with a 4x3 matrix, others with a 4x4 matrix.

Also, some examples show that you need a forth value for the vector's matrix of 1. What happens to this value when it's included in the output?

            [1 0 0 0]
[x y z 1] * [0 1 0 0] = [a b c d]
            [0 0 1 0]
            [2 4 6 1]

The parts I'm missing are:

  • What sizes my matrices should be
  • Compositing transformations by multiplying the transformation matrices together
  • Transforming 3D vectors with the resulting matrix

As I mostly just want to get this running, any psuedo-code would be great. Information about what matrix values perform what transformations is quite clearly defined on many pages, so need not be discussed here unless you're very keen :)

© Stack Overflow or respective owner

Related posts about language-agnostic

Related posts about vector