Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Compass heading from deviceorientation
Message
De
24/04/2014 12:00:25
 
 
À
24/04/2014 11:29:49
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
Information générale
Forum:
HTML5
Catégorie:
Problèmes de navigateur
Divers
Thread ID:
01598938
Message ID:
01598995
Vues:
21
>>>>
>>>>With that correction the heading does seems to remain fairly constant regardless of beta and gamma values. But changes on the x axis still result in the skip :-{
>>>>H
>>>
>>>
>
>>Current code:
>
function compassHeading2(alpha, beta, gamma , absolute) {
>>
>>    var _x = beta ? beta * degtorad : 0; // beta value
>>    var _y = gamma ? gamma * degtorad : 0; // gamma value
>>    var _z = alpha ? alpha * degtorad : 0; // alpha value
>>
>>    var cX = Math.cos(_x);
>>    var cY = Math.cos(_y);
>>    var cZ = Math.cos(_z);
>>    var sX = Math.sin(_x);
>>    var sY = Math.sin(_y);
>>    var sZ = Math.sin(_z);
>>
>>    // Calculate Vx and Vy components
>>    var Vx = -cZ * sY - sZ * sX * cY;
>>    var Vy = -sZ * sY + cZ * sX * cY;
>>
>>    // Calculate compass heading
>>    //var compassHeading = Math.atan(Vx / Vy);
>>    var compassHeading = Math.atan2(Vx ,Vy);
>>
>>    // Convert compass heading to use whole unit circle
>/*
>>    if (Vy < 0) {
>>        compassHeading += Math.PI;
>>    } else if (Vx < 0) {
>>        compassHeading += 2 * Math.PI;
>>    }
>*/
>>
>>    return compassHeading * (180 / Math.PI); // Compass Heading (in degrees)
>>}
>
>
>
>With .atan2() you don't need the if (Vy < 0) { part - in fact, as it is, the correction may be done twice. Try to comment that part out (like I did here).

I thought that might be the case and did, in fact, try running without it. Results still made no sense :-{
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform