# Rotation problems: Howto calculate shortest way?

## Recommended Posts

yap, i fail, i cant figure out howto make it think thats shortest way, it always fails with the 0.00 angle :/

i am not going with 360, i am going with radians[i am pretty sure ;? fix me if i am wrong.] {2*pi but that shouldnt matter.}

.. i think pics will tell you more.

and here how it should be

give me some ideas

PS. My paint skills, ftw!

##### Share on other sites

Could it be so easy that you've missed the fact that the yellow dot is not at angle 0 but rather 90° (or π/2 if you want). That's how the unit circle works anyway.

Broken link? PM me and I'll send you the file!

##### Share on other sites

some old function I used once for this, not sure if it works or not.

It returns an array, where [0] is direction and [1] is angle difference.

[0] can be 1 or -1 (-1 for left and 1 for right I think)

```Func _Between(\$s_Next_Rot, \$s_Cur_Rot)
Local \$Array[2]

If \$s_Cur_Rot > \$s_Next_Rot Then
If (\$s_Cur_Rot - \$s_Next_Rot) < 181 Then
\$Array[0] = 1
\$Array[1] = \$s_Cur_Rot - \$s_Next_Rot
Else
\$Array[0] = -1
\$Array[1] = ((\$s_Next_Rot + 360) - \$s_Cur_Rot)
EndIf
Else
If (\$s_Next_Rot - \$s_Cur_Rot) < 181 Then
\$Array[0] = -1
\$Array[1] = \$s_Next_Rot - \$s_Cur_Rot
Else
\$Array[0] = 1
\$Array[1] = ((\$s_Cur_Rot + 360) - \$s_Next_Rot)
EndIf
EndIf

Return \$Array
EndFunc```

[font="Impact"]Never fear, I is here.[/font]

##### Share on other sites

some old function I used once for this, not sure if it works or not.

It returns an array, where [0] is direction and [1] is angle difference.

[0] can be 1 or -1 (-1 for left and 1 for right I think)

```Func _Between(\$s_Next_Rot, \$s_Cur_Rot)
Local \$Array[2]

If \$s_Cur_Rot > \$s_Next_Rot Then
If (\$s_Cur_Rot - \$s_Next_Rot) < 181 Then
\$Array[0] = 1
\$Array[1] = \$s_Cur_Rot - \$s_Next_Rot
Else
\$Array[0] = -1
\$Array[1] = ((\$s_Next_Rot + 360) - \$s_Cur_Rot)
EndIf
Else
If (\$s_Next_Rot - \$s_Cur_Rot) < 181 Then
\$Array[0] = -1
\$Array[1] = \$s_Next_Rot - \$s_Cur_Rot
Else
\$Array[0] = 1
\$Array[1] = ((\$s_Cur_Rot + 360) - \$s_Next_Rot)
EndIf
EndIf

Return \$Array
EndFunc```
going to try that

EDIT: fails like my method i used earlier, if your rotation is like.. 5.20 and target is 0.89 it will go right, instead of going left :/

Could it be so easy that you've missed the fact that the yellow dot is not at angle 0 but rather 90° (or π/2 if you want). That's how the unit circle works anyway.

wasnt the point that it wasnt on exactly 0, was just example Edited by zutto

##### Share on other sites

0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

## Create an account

Register a new account