Home /  Sketchbook /  p5.js - Common Examples - Rotation between Vectors
  • Info

Overview

This is a p5.js sketch to test out an implementation of rotationBetweenVectors.

In particular, the function is pretty simple:

function rotationBetweenVectors(v1, v2){
  let h1 = v1.heading();
  let h2 = v2.copy().rotate(-h1);
  return h2.heading();
}

This function is available in my P5JsUtils class (code link).

Used this sketch to visualize the inflection points between positive and negative results, and sensitivty around values of PI.

Controls

Mouse

  • Click Toggles between showing the vectors and a shading of the rotation value from -PI to 0 (red) and 0 to PI (blue)

References:

Links:

  • Live View
  • Source on Github

Screenshot:

screenshot screenshot