import math


def calcErrorFromHandTracking(amplitude):
    """
    Calculate the error due to inaccuracy in hand tracking by calculating the
    RMSE of measured tremor amplitude between the three chosen hand landmarks.

    Note that this relies on the subject's fingers staying the same distance
    apart from each other throughout the video. Works best with MCP (first
    knuckle) landmarks, as they cannot be moved apart like fingers can.

    Returns the error, in +/- cm.
    """

    avg = sum(amplitude) / len(amplitude)

    rmse = 0
    for a in amplitude:
        rmse += (a - avg) ** 2
    rmse = math.sqrt(rmse / len(amplitude))

    # Divide by two to get +/- value, rather than total error value:
    return rmse / 2