VelocityTracker1D



A velocity tracker calculating velocity in 1 dimension.

Add displacement data points using addDataPoint, and obtain velocity using calculateVelocity.

Note: for calculating touch-related or other 2 dimensional/planar velocities, please use VelocityTracker, which handles velocity tracking across both X and Y dimensions at once.

Summary

Public constructors

VelocityTracker1D(isDataDifferential: Boolean)

Constructor to create a new velocity tracker.

Cmn

Public functions

Unit
addDataPoint(timeMillis: Long, dataPoint: Float)

Adds a data point for velocity calculation at a given time, timeMillis.

Cmn
Float

Computes the estimated velocity at the time of the last provided data point.

Cmn
Float
calculateVelocity(maximumVelocity: Float)

Computes the estimated velocity at the time of the last provided data point.

Cmn
Unit

Clears data points added by addDataPoint.

Cmn

Public properties

Boolean
Cmn

Public constructors

VelocityTracker1D

VelocityTracker1D(isDataDifferential: Boolean)

Constructor to create a new velocity tracker. It allows to specify whether or not the tracker should consider the data ponits provided via addDataPoint as differential or non-differential.

Differential data ponits represent change in displacement. For instance, differential data points of 2, -1, 5 represent: the object moved by "2" units, then by "-1" units, then by "5" units. An example use case for differential data points is when tracking velocity for an object whose displacements (or change in positions) over time are known.

Non-differential data ponits represent position of the object whose velocity is tracked. For instance, non-differential data points of 2, -1, 5 represent: the object was at position "2", then at position "-1", then at position "5". An example use case for non-differential data points is when tracking velocity for an object whose positions on a geometrical axis over different instances of time are known.

Parameters
isDataDifferential: Boolean

true if the data ponits provided to the constructed tracker are differential. false otherwise.

Public functions

addDataPoint

fun addDataPoint(timeMillis: Long, dataPoint: Float): Unit

Adds a data point for velocity calculation at a given time, timeMillis. The data ponit represents an amount of a change in position (for differential data points), or an absolute position (for non-differential data points). Whether or not the tracker handles differential data points is decided by isDataDifferential, which is set once and finally during the construction of the tracker.

Use the same units for the data points provided. For example, having some data points in cm and some in m will result in incorrect velocity calculations, as this method (and the tracker) has no knowledge of the units used.

calculateVelocity

fun calculateVelocity(): Float

Computes the estimated velocity at the time of the last provided data point.

The units of velocity will be units/second, where units is the units of the data points provided via addDataPoint.

This can be expensive. Only call this when you need the velocity.

calculateVelocity

fun calculateVelocity(maximumVelocity: Float): Float

Computes the estimated velocity at the time of the last provided data point.

The method allows specifying the maximum absolute value for the calculated velocity. If the absolute value of the calculated velocity exceeds the specified maximum, the return value will be clamped down to the maximum. For example, if the absolute maximum velocity is specified as "20", a calculated velocity of "25" will be returned as "20", and a velocity of "-30" will be returned as "-20".

Parameters
maximumVelocity: Float

the absolute value of the maximum velocity to be returned in units/second, where units is the units of the positions provided to this VelocityTracker.

resetTracking

fun resetTracking(): Unit

Clears data points added by addDataPoint.

Public properties

isDataDifferential

val isDataDifferentialBoolean