vectorAngle function

double vectorAngle(
  1. double ux,
  2. double uy,
  3. double vx,
  4. double vy,
)

Implementation

double vectorAngle(double ux, double uy, double vx, double vy) {
  var sign = ux * vy - uy * vx < 0 ? -1 : 1;
  var ua = sqrt(ux * ux + uy * uy);
  var va = sqrt(vx * vx + vy * vy);
  var dot = ux * vx + uy * vy;

  return sign * acos(clip(dot / (ua * va), -1, 1));
}