Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

Hi all,

I need a mathematical formula to determine whether given a starting angle and an ending angle, I need to determine whether it is "shorter" to go in a clock-wise direction or anti-clockwise.

For example:

starting angle: 50 degrees

ending angle: 60 degrees

It would be clockwise, as it's only 10 degrees in clockwise fashion where as it would 350 degrees if it would to go anti-clockwise to reach the 60 degree mark.

Is there some mathematical formula that can be devised which would return a result indicating a clockwise and anti-clockwise direction? Perhaps something which returns a positive or negative corresponding to each??

For a bit of context I'm a computer programmer and need to implement the logic, but my maths is failing me on this one!

Many thanks!

I need a mathematical formula to determine whether given a starting angle and an ending angle, I need to determine whether it is "shorter" to go in a clock-wise direction or anti-clockwise.

For example:

starting angle: 50 degrees

ending angle: 60 degrees

It would be clockwise, as it's only 10 degrees in clockwise fashion where as it would 350 degrees if it would to go anti-clockwise to reach the 60 degree mark.

Is there some mathematical formula that can be devised which would return a result indicating a clockwise and anti-clockwise direction? Perhaps something which returns a positive or negative corresponding to each??

For a bit of context I'm a computer programmer and need to implement the logic, but my maths is failing me on this one!

Many thanks!

Do more with

EXPERT OFFICE^{®} is a registered trademark of EXPERTS EXCHANGE^{®}

angle_difference = (angle1 - angle2) mod 360;

Perhaps if you can tell which language are you using I can help more. For example on C/Java languages families you sound put:

angle_difference = (angle1 - angle2) % 360;

angle1 is the bigger one and angle2 is the smaller one. If you want the anti-clockwize, just substract 360 and change the sign.

Regards.

So the formula I said is not exactly: when I said clock-wise I meant anti-click-wise and vice-versa.

## Premium Content

You need an Expert Office subscription to comment.Start Free Trial