hankel

fun List<Vector2>.hankel(window: Int, closed: Boolean): Matrix(source)

Constructs a Hankel-like matrix from the invoking list of Vector2 objects.

Each row in the resulting matrix represents sequential values from the list, organized into a window of a specified size. If the closed parameter is set to true, the indexing wraps around circularly to use elements beyond the boundaries of the list.

A Hankel matrix is a matrix where each ascending anti-diagonal from left to right is constant. In other words, elements along each anti-diagonal share the same value. In the classic form, Mi,j = Mi+1,j-1 for a traditional Hankel matrix. This function creates a "Hankel-like" structure by placing sequential elements from the input list along rows with a sliding window, where each row is shifted by one position relative to the previous row, creating the characteristic anti-diagonal pattern.

An anti-diagonal (also called a skew diagonal or counter diagonal) is a line of elements that runs from the top-right to bottom-left of a matrix, perpendicular to the main diagonal. For example, in a 3x3 matrix, the main diagonal contains elements at positions (0,0), (1,1), (2,2), while anti-diagonals run in the opposite direction: one anti-diagonal might contain (0,2), (1,1), (2,0). In general, elements on the same anti-diagonal satisfy i+j = constant.

Return

A Matrix containing the Hankel-like arrangement of the elements from the list. The matrix is of size 2n x window where n refers to the effective number of rows (original list size for circular, otherwise depends on window size).

Parameters

window

The window size determining the number of consecutive elements to include in each row of the resulting matrix. Must be greater than zero.

closed

A flag indicating whether the list should be treated as circular. If true, indexing wraps around at the boundaries; otherwise, it doesn't.

Throws

If the list is empty or if the window size is not greater than zero.