在下面的代码中,我想确保一条线相对于另一条线顺时针旋转。我想顺时针走的线有角度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
}
此代码在大多数情况下都有效,但在targetAngle低于 0 时会中断。