Saturday, October 15, 2011

Planes and their Normals

 Firstly, let us consider planes in 3 space. We all have a geometric idea of a what a plane is, but, it is always good to start with a good definition of any mathematical object that one is dealing with.

So, what is a plane? One definition that we can use is:


        Given a vector and a point, a plane is the set of all vectors which are perpendicular in direction to the given vector, and contain the given point.

Now, why would we pick such a weird definition? Well, here's why. We know a lot about perpendicular things, and if they're vectors, we can use the dot product in special ways to our advantage. Basically, if you have Euclidean Geometry, it usually helps to turn it into vectors, because that gives us an edge on the problems posed, because the dot product links Euclidean Geometry to coordinates. And, we have the cross product as well, which would give as a normal vector.



Let's try to use this definition to derive an equation for a plane from a given normal vector and a point.



Say the vector we are given is called $\vec{v}$, and the point is called $A$. Lets give these some more information:

$\vec{v} = <a,b,c>$
$A = (x_0, y_0, z_0)$

Let $\vec{w}$ be the position vector of $A$. And, let us introduce a second point, with a position vector of:

$\vec{m} = <x, y, z>$

The x, y and z are arbitrary and not fixed. We know (from our definition):

$(\vec{m}-\vec{w}) \cdot \vec{v} = 0$

This expands out to:

$a(x-x_0) + b(y-y_0) + c(z-z_0) = 0$


Which is a equation for the plane. Obviously, having the plane defined in terms of a normal (and a point) helped a lot since we we could use existing knowledge of the dot product. Now, lets see again why this is so useful.

Given two vectors, $\vec{v}$ and $\vec{w}$, find the equation of the plane they form.

Lets see, if want the equation of the plane, and we have two vectors, we'll need to get the normal vector from these, which is perpendicular to both $\vec{v}$ and $\vec{w}$... Oh yeah! The cross product! When you take the cross product of two vectors, the vector returned is perpendicular in direction to the argument vectors.

So, lets set some stuff up:

$\vec{v} = <v_x, v_y, v_z>$
$\vec{w} = <w_x, w_y, w_z>$

$\vec{v} \times \vec{w} = <v_yw_z - v_zw_y, v_zw_x - v_xw_z, v_xw_y-v_yw_x>$

This we can plug right into the our plane equation that we derived, and, we're done!

As you can see, defining planes in 3 space in terms of their normal vectors is an excellent idea since we can leverage existing knowledge in the field to vectors to kill problems. Also, vectors allow us to go from Euclidean geometry ($||v|| ||w|| cos \theta$) to algebra ($v_xw_x + v_yw_y + v_zw_z$) very easily.

Normals are used excessively in game development and graphics for areas such as lighting and shadows. In fact, it is used so much, a brilliant computer scientist (John Carmack) came up with the Fast Inverse Square Root  that uses Newton's method in a clever way.

For the people asking for more advanced stuff and less uselessly detailed solutions, I tried doing that this blog post (though it was still a relatively elementary topic), tell me what you think in the comments below :)

No comments:

Post a Comment