Help needed with matrix rotation math

Started by
11 comments, last by MenDAKE 16 years, 1 month ago
Okay, I think get what you mean about the Z component. I suppose I just ignore it by keeping at 0 at all times, right?

I'm unfortunately starting to get lost with your last point, though. Forgive my ignorance. Can you explain a bit more about why we're defining a plane? It's not super clear to me.
Advertisement
Take two vectors that aren't parallel. v1 and v2.

Now imagine all linear combinations of the two -- for all numbers a and b, look at what the value of a*v1 + b*v2 is.

To think about it concretely, hold up two fingers. Now imagine what points you can reach by adding any distance along the direction pointed by one finger, plus any distance along the direction pointed by another. You can use your index finger and your thumb to see this easily.

You could see how this is two dimensional? The set of "linear combinations of v1 and v2", or the points a*v1 + b*v2, is also known as the "span" of your vectors. (these are all just different ways of saying the same thing: span, linear combinations, or a*v1 + b*v2 for any number a and b).

So: two non-parallel vectors in this sense define a plane.

Now, this plane is rooted at (0,0,0) -- so it isn't quite an arbitrary plane -- so you need a third vector to offset the plane from (0,0,0). This produces an equation:

plane(a,b) = v0 + a*v1 + b*v2

If you are careful and make sure that v1 and v2 are at right angles, and are both length 1, then you have some really nice bonus properties.

Now, we can play with some math.

Remember how you dropped the z coordinate to move a point from (x,y,z) to the x,y plane? This is known as projecting your vector onto the plane.

It is a method of finding a point that is on the plane, such that the "height" vector from the point on the plane to the point off of the plane is at right angles to the plane. Whew. A way of thinking about it is that it is a "shadow" of the point on the plane.

The dot product is very useful for doing this.

(a,b,c) dot (x,y,z) is simply a*x + b*y + c*z -- it takes two vectors, and produces a number.

The beauty of the dot product is:
(w dot v1) times v1 (assuming v1 is length 1)
is the projection of w onto the line spanned by v1. (take all linear combinations of v1 -- or all multiples of v1. For any non-zero vector, this forms a line, right?)

(w dot v1) is like the x coordinate of a vector.

Look at (x,y,z) dot (1,0,0). It equals x.
And (x,y,z) dot (0,1,0) equals y.
And (x,y,z) dot (0,0,1) equals z.

Now try (x,y,z) dot (1,0,0) times (1,0,0) plus (x,y,z) dot (0,1,0) times (0,1,0).

It equals (x,y,0). That isn't a coincidence.

What I just did was find the point on the xy plane that is the projection of an arbitrary point (x,y,z) -- ie, (x,y,0).

This works so long as your vectors that define your plane are of length 1 and at right angles to each other.

So for a plane(a,b) = a*v1 + b*v2
we can project an arbitrary point (x,y,z) onto this plane via
(x,y,z)dot v1 * v1 + (x,y,z)dot v2 * v2

And that is a point on the plane(a,b) that is the projection of (x,y,z).

That works for planes that pass through (0,0,0). For arbitrary planes, we first shift (x,y,z) and the plane by our v0 vector, then do the projection trick, then shift everything back by our v0 vector.

projection(x,y,z) = (((x,y,z)-v0)dot v1 * v1 + ((x,y,z)-v0)dot v2 * v2) + v0

Viola!

Now, the next step is doing this with vectors.

Remember the definition of dot?

(a,b,c) dot (x,y,z)
= ax+by+cz

What happens when you multiply two vectors shaped matrix-like?

[x y z] * [a]           = [ax + by + cz]          [c]


Any lightbulbs going off? That should look like matrix math.

Arrange your matrix right, and you can make a matrix that projects a vector onto your plane!

Using a bit more mojo, you can even slip the translations in...


[Edited by - NotAYakk on April 6, 2008 1:16:38 AM]
Thanks for taking the time to explain all that. I haven't studied it yet, and it turns out I have to do some traveling, so I won't get to this for a few more days, but definitely intend to get back to it. It looks very, very helpful. I think I'm finally on track to start understanding rotations better.

This topic is closed to new replies.

Advertisement