vector3_dot_product


Description:

public float vector3_dot_product (float a, float b)

Calculates the dot product of the two 3 component vectors.

This can be used to determine the magnitude of one vector projected onto another. (for example a surface normal)

For example if you have a polygon with a given normal vector and some other point for which you want to calculate its distance from the polygon, you can create a vector between one of the polygon vertices and that point and use the dot product to calculate the magnitude for that vector but projected onto the normal of the polygon. This way you don't just get the distance from the point to the edge of the polygon you get the distance from the point to the nearest part of the polygon.

<note>If you don't use a unit length normal in the above example then you would then also have to divide the result by the magnitude of the normal</note>

The dot product is calculated as:

 (a->x * b->x + a->y * b->y + a->z * b->z)

For reference, the dot product can also be calculated from the angle between two vectors as:

 |a||b|cos𝜃

Parameters:

a

Your first 3 component vector

b

Your second 3 component vector

Returns:

The dot product of two vectors.


Namespace: Cogl
Package: doc