Jump to content
Sign in to follow this  
zutto

Rotation problems: Howto calculate shortest way?

Recommended Posts

zutto

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.

Posted Image

and here how it should be

Posted Image

give me some ideas :D

PS. My paint skills, ftw!

Share this post


Link to post
Share on other sites
monoceres

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 this post


Link to post
Share on other sites
Alek

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 this post


Link to post
Share on other sites
zutto

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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.