I have two angles: from
, to
and clockwise direction. And defined angle. Angles are between 0 and 360 deg. I need a function that returns is defined angle is between from
and to
angles.
For example:
function isInRange(from, to, angle){
...
}
isInRange(30, 330, 90); // true
isInRange(30, 330, 0); // false
isInRange(330, 30, 90); // false
isInRange(330, 30, 0); // true
Help please)
First make sure that the angles are comparable, then it's a simple range comparison:
function isInRange(from, to, angle){
// make sure to >= from
while (to < from) to += 360;
// make sure angle >= from
while (angle < from) angle += 360;
// compare
return angle >= from && angle <= to;
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments