I have converted a c++ code into javascript which calculates angle between 3 points. Though it is working properly I do not understand math behind it.
function angle(a, b, c) {
var ab = { x: b.x - a.x, y: b.y - a.y };
var cb = { x: b.x - c.x, y: b.y - c.y };
var dot = (ab.x * cb.x + ab.y * cb.y); // dot product
var cross = (ab.x * cb.y - ab.y * cb.x); // cross product
var alpha = -Math.atan2(cross, dot);
if (alpha < 0) alpha += 2 * Math.PI;
return alpha;
}
What is the use of dot and cross product here? How does atan2 use cross and dot products to calculate angle?