2

I have 2 Pose representing 2 positions of the camera and I want to get the difference between their azimuth angles.
The older pose is retrieved from an anchor set with the older camera pose, so that I shouldn't get errors from updates of ARCore's world understanding.
The newer pose is retrieved from the current frame.

I tried to use this formula from wikipedia:

psi = atan2(
    2*(qw*qz + qx*qy),
    1-2*(qy*qy + qz*qz)
)

Then I substract the older angle from the newer, with no success: when I move the phone to modify the pitch angle only, the result I get also varies.

I think it didn't work because it assumes +Z to be the vertical axis, whereas +Y is the vertical axis in ARCore. So I rotated the axes in the formula so that the vertical axis is Y :

psi = atan2(
    2*(qw*qy + qz*qx),
    1-2*(qx*qx + qy*qy)
)

It still doesn't work, the result still varies when I change the pitch only. Apparently this is not the right transformation to do.

How can I calculate the difference in azimuth angle between the 2 poses of the camera ?

This might actually be a question for Mathematics Stack Exchange, but I'm not sure if I'm misunderstanding ARCore or the maths, so here it is.

1 Answer 1

1

Use the following approach to calculate azimuth that always measured in two dimensions:

public float getAzimuth(PointF aim) {

    float angle = Math.toDegrees(Math.atan2(aim.x - x, aim.y - y));

    // the range of ± 90.0° must be corrected...

    if(angle < 0.0) {
        angle += 360.0;
    }
    return angle;
}

...the following approach to calculate a distance:

float distance = Math.sqrt((x2 – x1) / 2.0 + 
                           (y2 – y1) / 2.0 + 
                           (z2 – z1) / 2.0); 

...and the following approach to calculate a plunge:

float plunge = Math.asin((z2 – z1) / distance)
1
  • 1
    Ok, it was actually incredibly simple. I can't explain why I was so convinced I needed to use the quaternions (I actually managed to make it work, but it's certainly much less efficient). I cannot try it right now, but I will probably accept this answer tomorrow after verifying it does work.
    – Annyo
    Sep 19, 2019 at 20:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.