check if angle is between angles `from` and `to` with clockwise direction

Artem Svirskyi

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)

Guffa

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.

edited at
0

Comments

0 comments
Login to comment

Related

Getting closest angle from array of angles clockwise and anticlockwise

calculate the angle between 2 vectors, clockwise and from 0 to 2*pi

Calculate angle (clockwise) between two points

Calculating difference in angle between two angles

Determine if Angle is Between 2 Other Angles

MYSQL - Calculating if an angle is between two angles

How to get clockwise angle between 2 angle on unit circle

JavaScript - Find turn direction from two angles

Calculation - Direction values from rotation angles

Tibia angle from Quaternion on a plane, Euler Angles

Getting the angle from a direction vector?

Calculate angles that are in degrees (clockwise) to radians (counter clockwise)

Find clockwise angle between two points with respect to an arbitrary origin

How to find the clockwise angle between two vectors in python?

How to rotate NSButton in clockwise direction from its center point in Cocoa?

Sorting points in a clockwise direction

How to set new turtles direction from average of 2 angles in netlogo

How to determine an 360° angle from relative direction?

Get angle of direction from GCExtendedGamepad.leftThumbstick

Find an angle representing the direction of travel from origin coordinates

Determine whether the direction of a line segment is clockwise or anti clockwise

Getting the angle from 3 vectors, without excluding non-reflex of obtuse angles

Rotate Elements of Matrix in counter clockwise direction in java

Set the direction of network circle graph to clockwise

How to detect if mouse is moving in clockwise direction

How to followPath: in clockwise direction for rectangular shape path?

Rotating column values in a table in clockwise direction

Cycle through a set of numbers in clockwise direction

Summarize all intersection points by clockwise direction