perjantai 24. elokuuta 2012

Dot product explained differently

Dot product is one of the "tools" that is hard to avoid if one is programming anything related to 3D. I have found several attempts to explain the dot product. However, many of them are strictly mathematical. The mathematical explanation of dot product is useful only for those who can read and understand mathematical presentations. This presentation is not aimed to those people :)

This is a one way to see the dot product from a very practical point of view.

Let's see a figure from Wikipedia about dot product:

The figure shows the relation of the dot product and the cosine. For example, if you have two unit vectors (eg. vectors with length 1) and the angle between them is 45 degrees, then the result of dot product is the same as cosine of 45, which is about 0.7

Now, let's draw the same figure a little bit differently.

The vector B is now a plane normal. Now, the dot product of vector A and the plane normal gives us the distance between the vector (a point) A and the plane defined by the normal (yes, a normal itself defines a plane where one of the plane's points is in the origin. Let's call that a "normal" plane").

This is very handy indeed. The dot product can be used as a tape measure.

But this works only if our plane goes through the origin. What if our plane is not in origin? Well, the solution is simple. The distance from any point to any plane is:

the distance between the point and the "normal" of the plane + the distance from the plane to the "normal" plane.

More formally:

dotProduct(the point, the normal ) + dotProduct(the point of the plane, the normal)

I hope this helps someone.

Ei kommentteja:

Lähetä kommentti