RelativeAngle

This API enables the user to get updates describing the relative heading and pitch of a mobile device.

The RelativeAngle angles always start at a value of 0 and, as the device is rotated, the relative angles are updated in degrees. Rotating the device to the left causes the relative heading value to decrease, whereas rotating to the right causes the value to increase. Tilting the device downward causes the relative pitch value to decrease, whereas upward tilting causes the value to increase

Use this API if you need both relative heading and pitch at the same time. Otherwise, refer to the RelativeHeading or RelativePitch APIs.

When motion events are not available on the device, RelativeAngle events are polyfilled with pan touch events.

Example

var relativeAngle = new MotionStack.RelativeAngle();

relativeAngle.start(function (e) {
  console.log(e.heading);

  if (Math.abs(e.heading) > 360) {
    relativeAngle.stop();
  }
});

Constructor

new MotionStack.RelativeAngle([options])

Create a new RelativeAngle instance object.

Argument Type Description
options Object Options to pass in for the new RelativeAngle instance (optional)

  • continuous {Boolean}
  • Determines whether the angles can grow indefinitely. When this is false, the value of relative heading is bounded between 0 and 360 degrees, and relative pitch is bounded between -180 and +180 degrees.


    Default: false

  • direction {String}
  • Designates which relative angle to calculate.

    • "heading"
    • Update the relative heading angle.
    • "pitch"
    • Update the relative pitch angle.
    • "all"
    • Update both relative heading and pitch angles.


    Default: "all"

  • fireOnAnimationFrame {Boolean}
  • Only emit the latest event within requestAnimationFrame intervals.


    Default: false

  • touchDamping {Number}
  • A multiplication coefficient used to scale the pan velocity. Used only for the touch polyfill when source = "touch".


    Default: 0.03

  • headingRange {Number}
  • The maximum allowed magnitude of the heading angle. That is, the heading angle is restricted between -headingRange <= heading <= headingRange.


    Default: Infinity

  • pitchRange {Number}
  • The maximum allowed magnitude of the pitch angle. That is, the pitch angle is restricted between -pitchRange <= pitch <= pitchRange.


    Default: Infinity

  • source {String}
  • The source used to calculate the reported data in order of approximation. If the specified source is not available, then the next available source is used.

    • "detectCompass" determines which is the best source estimate to use.
    • "rawOrientation" browser estimate.
    • "sensorFusion" sensor fusion via a Kalman filter.
    • "filteredOrientation" dynamic low-pass filter on the browser estimate.
    • "gravityPolyfill" accelerometer gravity estimate.
    • "touch" touch sensor.


    Default: "detectCompass"

var relativeAngle = new MotionStack.RelativeAngle({continuous: true});

Instance Methods

start(callback, [context])

Start receiving relative angle updates.

Argument Type Description
callback Function Callback function that receives an object as an argument

  • function(e)
  • e.heading {Number}
    Current heading angle of the device as measured from the initial heading when the start() method was first invoked on the given instance
  • e.pitch {Number}
    Current pitch angle of the device as measured from the initial pitch when the start() method was first invoked on the given instance
  • e.timeStamp {Number}
    The time in milliseconds when the data is collected
  • e.source {String}
    The source used to calculate the reported data.

    • "rawOrientation" browser estimate.
    • "sensorFusion" sensor fusion via a Kalman filter.
    • "filteredOrientation" dynamic low-pass filter on the browser estimate.
    • "gravityPolyfill" accelerometer gravity estimate.
    • "touch" touch sensor.

context Object Context in which to invoke the callback (optional).
relativeAngle.start(function(e) {
  console.log(e.pitch);
});

stop()

Stop relative heading updates.

relativeAngle.stop();

Source

src/interfaces/RelativeAngle.js