In the code below, I want to make sure a line is rotating clockwise in relation to another line. The line I want to go clockwise has angle targetAngle.
var dX = line.start.x - someOtherPoint.x;
var dY = line.start.y - someOtherPoint.y;
var lastAngle = Math.atan2(dY, dX);
var dX = line.start.x - line.end.x;
var dY = line.start.y - line.end.y;
var targetAngle = Math.atan2(dY, dX);
if (targetAngle < lastAngle) {
// is going counter clockwise
} else {
// is going clockwise
}
This code works in most cases, but breaks when targetAngle has gone below 0.
Changing this:
to this:
seems to do the trick.