Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Compass Headings
Message
De
20/11/2016 05:11:15
 
 
À
19/11/2016 12:42:03
Information générale
Forum:
Games
Catégorie:
Question
Divers
Thread ID:
01643702
Message ID:
01643719
Vues:
29
>General sort of question:
>
>I'm drawing a compass and need to determine the 'shortest' direction in which to rotate the compass (clockwise or anti-clockwise) between old and new bearings (in degrees).
>In most cases it is simple but when the old and new values span the 0 degree point those solutions don't work.....
>
>Anyone got a foolproof algorithm (language doesn't matter - just the logic)

Not perfect, you will need to add some more logic since it gives the wrong result for some extreme values. But a step in the right direction. Unfortunately I don't have the time to fix my code.

Since some people defines a full circle as -180° to + 180° while others defines it as 0° - 360°, this function tries to accommodate both definitions.
Lparameters tnAng1, tnAng2
Local lnDirection, lnAngle
If m.tnAng1 < 0
   m.tnAng1 = m.tnAng1 + 360
Endif
If m.tnAng2 < 0
   m.tnAng2 = m.tnAng2 + 360
Endif
m.tnAng1 = m.tnAng1 % 360
m.tnAng2 = m.tnAng2 % 360
m.lnAngle = m.tnAng1 - m.tnAng2
if m.lnAngle < 0
   m.lnAngle = 360 + m.lnAngle 
Endif
If m.lnAngle > 180
   m.lnAngle = m.lnAngle %180 
   m.lnDirection = -1
Else
   m.lnDirection = 1
Endif
Return m.lnDirection * m.lnAngle
If you manage to fix my code, please show us the result,
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform