# angle difference in both directions?

Get help using Construct 2

### » Sun Nov 09, 2014 6:42 pm

How do i get the difference between 2 angles both clockwise and counterclockwise?

I want to compare the 2 to test if it's quicker to rotate an object left or right from its current angle to its target angle in degrees.

I thought you could negate the anglediff expression but it still only calculates the shortest difference.

Thanks.
B
43
S
23
G
21
Posts: 735
Reputation: 12,132

### » Mon Nov 10, 2014 2:47 am

This will give a signed angle diff between two angles.
angle(0,0,cos(a-b),sin(a-b))

It's in the range of -180 to 180. It always picks the shortest distance but it's negative if CCW and positive if CW.

Alternatively you could leverage the CW and CCW conditions or calculate if the angle diff is CW or CCW with
(sin(a-b)<0?-1:1)

global sign=1
global short_angdiff=0
global long_angdiff=0

every tick
--- set sign to (sin(a-b)<0?-1:1)
--- set short_angdiff to anglediff(a,b)*sign
--- set long_angdiff to (360-anglediff(a,b))*-1*sign
B
94
S
33
G
128
Posts: 5,489
Reputation: 81,541

### » Mon Nov 10, 2014 9:35 am

Brilliant as always, thanks for your help.
B
43
S
23
G
21
Posts: 735
Reputation: 12,132

### » Mon Nov 10, 2014 10:03 am

our R0J0hound is always there to help bless
B
262
S
48
G
15
Posts: 2,009
Reputation: 42,183

Return to How do I....?

### Who is online

Users browsing this forum: No registered users and 33 guests