def sort_UnitVector(a, b):
    """Sort UnitVector objects by how many rotations their reference frame is away from
    the Newtonian frame.
    """
    if a.frame == b.frame:
        return (a.i > b.i) - (a.i < b.i)
    else:
        return (len(a.frame.ref_frame_list) > len(b.frame.ref_frame_list)) -\
            (len(a.frame.ref_frame_list) < len(b.frame.ref_frame_list))