Creating a Random Tangent

From C4 Engine Wiki

Jump to: navigation, search

The following code snippet generates a vector that is perpendicular to a given normal direction, but is randomly oriented in the plane.

Vector3D CreateRandomTangent(const Vector3D& normal)
{
    Vector3D tangent = Math::CreatePerpendicular(normal);
    tangent.RotateAboutAxis(Math::RandomFloat(K::two_pi), normal);
    return (tangent);
}
Personal tools