Angle Between Two Vectors (VEX)

The angle \( \theta \) is the inverse cosine of the fraction of dot product of the vectors \(\vec{a}\) and \(\vec{b}\) and the product of the magnitudes of \(\vec{a}\) and \(\vec{b}\).

\(\theta = \cos^{-1}\biggl({{\vec{a} \bullet \vec{b}} \over {\vert \vec{a} \vert\vert \vec{b} \vert}}\biggr)\)

In VEX code:

vector a = v@vector_a;
vector b = v@vector_b;

float angle;
angle = acos( (dot(a,b)) / (length(a)*length(b)) ); //radians
angle *= 180/PI; //convert to degrees

If you’re interested in why this is true, here’s a few links to helpful resources:

https://www.cuemath.com/geometry/angle-between-vectors/

https://www.youtube.com/watch?v=bbBGgHDhmVg

Previous
Previous

Simple way to automate exports in Houdini with Python

Next
Next

Procedural attribute remap to 0-1 space