Proposal to add unit quaternion representation to the Device Orientation event.

Currently Device Orientation API provides an Euler angles based
representation, which in practice suffers from a number of issues as
summarized below. Hence this proposal to add a quaternion representation to
the device orientation event. A unit quaternion represents a rotation of A
radians around the unit vector [nx, ny, nz] : q = [x y z w] = [ nx*sin(A/2)
ny*sin(A/2) nz*sin(A/2) cos(A/2) ]. Here are some considerations why this
is useful:

1. Because Euler angles representations are difficult to compose developers
often end up converting them to other representations like quaternions or
rotation matrices. This extra conversion seems unnecessary especially on
platforms where the Euler angles are obtained via a quaternion
representation in the first place, e.g. on Android.

2. Using quaternion representation it is significantly easier to compute
'screen adjusted' orientation, i.e. taking into account the
portrait/landscape orientation of the actual page (using the Screen
Orientation API).

3. Intrinsic Euler rotations tend to have implementations that are not
always consistent. For example currently Safari and Firefox don't follow
the specification for some positions.

4. Euler angles have an additional degree of freedom when beta=+-90 degrees
(so-called gimbal lock situation), making multiple angle combinations all
correspond to the same orientation in space.

Proposed interface changes:

[Callback, NoInterfaceObject]
interface OrientationQuaternion {
  readonly attribute double x;
  readonly attribute double y;
  readonly attribute double z;
  readonly attribute double w;
}

[Constructor(DOMString type, optional DeviceOrientationEventInit
eventInitDict)]
interface DeviceOrientationEvent : Event {
  readonly attribute double? alpha;
  readonly attribute double? beta;
  readonly attribute double? gamma;
  readonly attribute boolean absolute;
  readonly attribute OrientationQuaternion? quaternion;
}

Tim

Received on Wednesday, 16 July 2014 14:30:17 UTC