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 8279491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:21:53+00:00 2026-06-08T09:21:53+00:00

I have a record session for my application. When user started a record session

  • 0

I have a record session for my application. When user started a record session I start collecting data from device’s CMMotionManager object and store them on CoreData to process and present later. The data I’m collecting includes gps data, accelerometer data and gyro data. The frequency of data is 10Hz.

Currently I’m struggling to calculate the lean angle of device with motion data. It is possible to calculate which side of device is land by using gravity data but I want to calculate right or left angle between user and ground regardless of travel direction.

This problem requires some linear algebra knowledge to solve. For example for calculation on some point I must calculate the equation of a 3D line on a calculated plane. I am working on this one for a day and it’s getting more complex. I’m not good at math at all. Some math examples related to the problem is appreciated too.

  • 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-06-08T09:21:57+00:00Added an answer on June 8, 2026 at 9:21 am

    It depends on what you want to do with the collected data and what ways the user will go with that recording iPhone in her/his pocket. The reason is that Euler angles are no safe and especially no unique way to express a rotation. Consider a situation where the user puts the phone upright into his jeans’ back pocket and then turns left around 90°. Because CMAttitude is related to a device lying flat on the table, you have two subsequent rotations for (pitch=x, roll=y, yaw=z) according to this picture:

    • pitch +90° for getting the phone upright => (90, 0, 0)
    • roll +90° for turning left => (90, 90, 0)

    But you can get the same position by:

    • yaw +90° for turning the phone left (0, 0, 90)
    • pitch -90° for making the phone upright (-90, 0, 90)

    You see two different representations (90, 90, 0) and (-90, 0, 90) for getting to the same rotation and there are more of them. So you press Start button, do some fancy rotations to put the phone into the pocket and you are in trouble because you can’t rely on Euler Angles when doing more complex motions (s. gimbal lock for more headaches on this 😉

    Now the good news: you are right linear algebra will do the job. What you can do is force your users to put the phone in always the same position e.g. fixed upright in the right back pocket and calculate the angle(s) relative to the ground by building the dot product of gravity vector from CMDeviceMotion g = (x, y, z) and the postion vector p which is the -Y axis (0, -1, 0) in upright position:

    g • x = x*0 + y*(-1) + z*0 = -y = ||g||*1*cos (alpha)

    => alpha = arccos (-y/9.81) as total angle. Note that gravitational acceleration g is constantly about 9.81

    To get the left-right lean angle and forward-back angle we use the tangens:

    alphaLR = arctan (x/y)

    alphaFB = arctan (z/y)


    [UPDATE:]

    If you can’t rely on having the phone at a predefined postion like (0, -1, 0) in the equations above, you can only calculate the total angle but not the specific ones alphaLR and alphaFB. The reason is that you only have one axis of the new coordinate system where you need two of them. The new Y axis y’ will then be defined as average gravity vector but you don’t know your new X axis because every vector perpedicular to y’ will be valid.

    So you have to provide further information like let the users walk a longer distance into one direction without deviating and use GPS and magnetometer data to get the 2nd axis z’. Sounds pretty error prone in practise.

    The total angle is no problem as we can replace (0, -1, 0) with the average gravity vector (pX, pY, pZ):

    g•p = xpX + ypY + zpZ = ||g||||p||*cos(alpha) = ||g||^2*cos(alpha)

    alpha = arccos ((xpX + ypY + z*pZ) / 9.81^2)


    Two more things to bear in mind:

    • Different persons wear different trowsers with different pockets. So the gravity vector will be different even for the same person wearing other clothes and you might need some kind of normalisation
    • CMMotionManager does not work in the background i.e. the users must not push the standby button
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an asp.net application c# that uses session state to store a variable
If i already have record with the exact same data in mysql database i
I have a record that came from the follow linq query: using (var context
I have a record set with hundreds of rows. when a user clicks the
I have a record store of items which have (name, quantity, owner, status) Now
I have a record store which holds a list of shopping items i am
I have two tables, users and hra. A user can only have one record
There is a problem with session variables in my web-application. I have several types
I have an application that shows some data in p:DataTable.... This table is accessible
In my MVC application I have a page for a user editing their account

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.