This python function converts cartesian coordinates to barycentric coordinates for any point belonging to a unit hypercube in dimension . The hypercube is defined as follows,
The function car2bar()
takes the cartesian coordinates of any point within the hypercube expressed as a column vector. This function returns the barycentric coordinates linked to the vertices of . The weights of the barycentric coordinates are ordered based on the binary encoding of the vertex index. For example, the following code converts the cartesian coordinates car
to the barycentric coordinates bar
in dimension ,
>>> import numpy as np
>>> car = np.array([[0], [1]])
>>> bar = car2bar(car)
>>> print(bar)
[[0.]
[1.]
[0.]
[0.]]
The vertices coordinates are obtained based on the binary decomposition of their respective indexes,
The function can be used for a non unit hypercube by normalizing the cartesian coordinates between and .