문제

The yaw pitch and roll we get from the android's SensorManager.getOrientation() are all for the Y axis of the phone. By this i mean, the yaw and pitch say where the Y-axis points, and the roll is about the Y axis. (and my screen orientation is fixed to landsape, so the Y axis doesnt change). But what i want is the yaw pitch and roll of the negative Z axis (points into the phone), more like if my phone screen is a landscape window in a cockpit of a plane, what would the yaw pitch and roll be?

도움이 되었습니까?

해결책

If I understand what you're saying, you are seeing the current yaw pitch and roll being return as if the +y axis were the default 'front' vector and the +z axis were the default 'up' vector. You would like to do a coordinate transform such that your yaw, pitch, and roll are calculated with the -z axis as the default 'front' vector and the +x vector as the default 'up' vector.

First, you'll need to compute the current front and up vectors from your yaw, pitch and roll in the current configuration. This can be done using 3D rotation matrices: http://en.wikipedia.org/wiki/Rotation_matrix#Rotations_in_three_dimensions

Use the yaw angle to rotate about z, pitch as a rotation about x, and roll as a rotation about y. Multiply these matrices together, then multiply the front vector (0, 1, 0) and up vector (0, 0, 1) by the result to get your new front and up vectors.

Next you'll need to compute the new yaw, pitch, and roll angles. Yaw is the angle between the front vector projected into the yz plane (set x value to 0) and the -z vector (0, 0, -1), pitch is the angle between the front vector projected onto the xz plane and the -z vector, and roll is the angle between the up vector projected onto the xy plane and the +x vector (1, 0, 0). If we let Fx = the x component of the front vector, Fy be the y component, and so on, we get:

yaw   = acos ( -z dot (0,  Fy, Fz) ) / sqrt(Fy*Fy + Fz*Fz)
pitch = acos ( -z dot (Fx, 0,  Fz) ) / sqrt(Fx*Fx + Fz*Fz)
roll  = acos ( +x dot (Ux, Uy, 0 ) ) / sqrt(Ux*Ux + Uy*Uy)

You should be able to do this for other vectors if I've chosen the wrong ones.

다른 팁

The body axes conventions used in Android are not the same as used in aerospace (for good reasons). The x-axis of a "plane" is equivalent to the "y" axis of and Android device (and likewise x axis is related to y axis, positive or negative depending on ENU ro NED conevntions). A good article on Yaw Pitch ans Roll conventions can be found here, and may be a start toward answering your question: http://www.sensorplatforms.com/understanding-orientation-conventions-mobile-platforms/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top