Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Compass heading from deviceorientation
Message
From
24/04/2014 11:29:49
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
General information
Forum:
HTML5
Category:
Browser issues
Miscellaneous
Thread ID:
01598938
Message ID:
01598985
Views:
26
>>>
>>>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).

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform