Index: spec-source-orientation.html =================================================================== RCS file: /sources/public/geo/api/spec-source-orientation.html,v retrieving revision 1.42 diff -u -r1.42 spec-source-orientation.html --- spec-source-orientation.html 7 Oct 2011 17:19:34 -0000 1.42 +++ spec-source-orientation.html 21 Oct 2011 15:57:05 -0000 @@ -150,6 +150,7 @@
  • 5.1 Use-Cases
  • 5.2 Requirements +
  • 6 Worked Example
  • Acknowledgments
  • References @@ -594,6 +595,407 @@

    5.2.4 The specification must be agnostic to the underlying sources of orientation and motion data.

    5.2.5 The specification must use the existing DOM event framework.

    +

    Worked Example

    + +

    This section is non-normative. + +

    The following worked example is intended as an aid to users of the + DeviceOrientation event. + +

    Section 2 provided an example of using the + DeviceOrientation event to obtain a compass heading when the device is held + with the screen horizontal. This example shows how to determine the compass + heading that the user is 'facing' when holding the device with the screen + approximately vertical in front of them. An application of this is an + augmented-reality system. + +

    More precisely, we wish to determine the compass heading of the horizontal + component of a vector which is orthogonal to the device's screen and pointing + out of the back of the screen. + +

    If r represents this vector in the rotated device + body frame xyz, then + + r + = + + ( + + 0 + 0 + -1 + + ) + + + +

    The transformation of r due to the rotation about + the z axis can be represented by the following rotation matrix. + +

    + + A + = + + ( + + + cos(α) + -sin(α) + 0 + + + sin(α) + cos(α) + 0 + + + 0 + 0 + 1 + + + ) + + + +

    The transformation of r due to the rotation about + the x axis can be represented by the following rotation matrix. + +

    + + B + = + + ( + + + 1 + 0 + 0 + + + 0 + cos(β) + -sin(β) + + + 0 + sin(β) + cos(β) + + + ) + + + +

    The transformation of r due to the rotation about + the y axis can be represented by the following rotation matrix. + +

    + + C + = + + ( + + + cos(γ) + 0 + sin(γ) + + + 0 + 1 + 0 + + + -sin(γ) + 0 + cos(γ) + + + ) + + + +

    If R resresents the vector r + in the earth frame XYZ, then since the inital body frame is aligned with the + earth, R is as follows. + +

    + + R = A B C r + + +

    + + R + = + + ( + + + cos(α) + -sin(α) + 0 + + + sin(α) + cos(α) + 0 + + + 0 + 0 + 1 + + + ) + + + ( + + + 1 + 0 + 0 + + + 0 + cos(β) + -sin(β) + + + 0 + sin(β) + cos(β) + + + ) + + + ( + + + cos(γ) + 0 + sin(γ) + + + 0 + 1 + 0 + + + -sin(γ) + 0 + cos(γ) + + + ) + + + ( + + 0 + 0 + -1 + + ) + + + +

    + + R + = + + ( + + + cos(α) + -sin(α) + 0 + + + sin(α) + cos(α) + 0 + + + 0 + 0 + 1 + + + ) + + + ( + + + 1 + 0 + 0 + + + 0 + cos(β) + -sin(β) + + + 0 + sin(β) + cos(β) + + + ) + + + ( + + -sin(γ) + 0 + -cos(γ) + + ) + + + +

    + + R + = + + ( + + + cos(α) + -sin(α) + 0 + + + sin(α) + cos(α) + 0 + + + 0 + 0 + 1 + + + ) + + + ( + + -sin(γ) + sin(β) cos(γ) + -cos(β) cos(γ) + + ) + + + +

    + + R + = + + ( + + + - + cos(α) + sin(γ) + - + sin(α) + sin(β) + cos(γ) + + + - + sin(α) + sin(γ) + + + cos(α) + sin(β) + cos(γ) + + + -cos(β) + cos(γ) + + + ) + + + +

    The compass heading θ is given by + +

    + + θ + = + tan - 1 + ( + R x + R y + ) + = + tan - 1 + ( + + - + cos ( α ) + sin ( γ ) + - + sin ( α ) + sin ( β ) + cos ( γ ) + + + - + sin ( α ) + sin ( γ ) + + + cos ( α ) + sin ( β ) + cos ( γ ) + + ) + + +

    provided that β and + γ are not both zero. + +

    As a consistency check, if we set + γ=0, then + +

    + + θ + = + tan - 1 + ( + + - + sin ( α ) + sin ( β ) + + + cos ( α ) + sin ( β ) + + ) + = + -α + + +

    as expected. +

    Acknowledgments

    Lars Erik Bolstad, Dean Jackson, Claes Nilsson, George Percivall, Doug Turner, Matt Womer