Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6069125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:47:19+00:00 2026-05-23T09:47:19+00:00

Im creating an application where i need to position a ImageView depending on the

  • 0

Im creating an application where i need to position a ImageView depending on the Orientation of the device.
I use the values from a MagneticField and Accelerometer Sensors to calculate the device orientation with

SensorManager.getRotationMatrix(rotationMatrix, null, accelerometerValues, magneticFieldValues)
SensorManager.getOrientation(rotationMatrix, values);
double degrees = Math.toDegrees(values[0]);

My problem is that the positioning of the ImageView is very sensitive to changes in the orientation. Making the imageview constantly jumping around the screen. (because the degrees change)

I read that this can be because my device is close to things that can affect the magneticfield readings. But this is not the only reason it seems.

I tried downloading some applications and found that the “3D compass” and “Compass” remains extremely steady in its readings (when setting the noise filter up), i would like the same behavior in my application.

I read that i can tweak the “noise” of my readings by adding a “Low pass filter“, but i have no idea how to implement this (because of my lack of Math).

Im hoping someone can help me creating a more steady reading on my device, Where a little movement to the device wont affect the current orientation.
Right now i do a small

if (Math.abs(lastReadingDegrees - newReadingDegrees) > 1) { updatePosition() }

To filter abit of the noise. But its not working very well 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:47:19+00:00Added an answer on May 23, 2026 at 9:47 am

    Though I havn’t used the compass on Android, the basic processing shown below (in JavaScript) will probably work for you.

    It’s based on the low pass filter on the accelerometer that’s recommended by the Windows Phone team with modifications to suit a compass (the cyclic behavior every 360″).

    I assume the compass reading is in degrees, a float between 0-360, and the output should be similar.

    You want to accomplish 2 things in the filter:

    1. If the change is small, to prevent gitter, gradually turn to that direction.
    2. If the change is big, to prevent lag, turn to that direction immediatly (and it can be canceled if you want the compass to move only in a smooth way).

    For that we will have 2 constants:

    1. The easing float that defines how smooth the movement will be (1 is no smoothing and 0 is never updating, my default is 0.5). We will call it SmoothFactorCompass.
    2. The threshold in which the distance is big enough to turn immediatly (0 is jump always, 360 is never jumping, my default is 30). We will call it SmoothThresholdCompass.

    We have one variable saved across the calls, a float called oldCompass and it is the result of the algorithm.

    So the variable defenition is:

    var SmoothFactorCompass = 0.5;
    var SmoothThresholdCompass = 30.0;
    var oldCompass = 0.0;
    

    and the function recieves newCompass, and returns oldCompass as the result.

    if (Math.abs(newCompass - oldCompass) < 180) {
        if (Math.abs(newCompass - oldCompass) > SmoothThresholdCompass) {
            oldCompass = newCompass;
        }
        else {
            oldCompass = oldCompass + SmoothFactorCompass * (newCompass - oldCompass);
        }
    }
    else {
        if (360.0 - Math.abs(newCompass - oldCompass) > SmoothThresholdCompass) {
            oldCompass = newCompass;
        }
        else {
            if (oldCompass > newCompass) {
                oldCompass = (oldCompass + SmoothFactorCompass * ((360 + newCompass - oldCompass) % 360) + 360) % 360;
            } 
            else {
                oldCompass = (oldCompass - SmoothFactorCompass * ((360 - newCompass + oldCompass) % 360) + 360) % 360;
            }
        }
    }
    

    I see that the issue was opened 5 months ago and probably isn’t relevant anymore, but I’m sure other programmers might find it useful.

    Oded Elyada.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a pretty standard business application in WPF. I need to use
I am creating a window application that need to use sql server database. I
I'm creating a WPF application where I need to use custom fonts. A created
I'm creating an application in Objective-C and I need to get the metadata from
I am creating an application were I need to scan a directory hive to
We are creating an XBAP application that we need to have rounded corners in
I am creating a C# Windows Mobile application that I need to programmatically invoke
I am creating a Console Application, in that I need to Call a Method,
I'm creating a reporting application, and our customers are going to need to generate
We are creating a rails application for an already existing database. We need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.