barycentricCoordinates

pyvsim.Utils.barycentricCoordinates(p, p1, p2, p3)[source]

Returns the barycentric coordinates of points, given the triangles where they belong.

For more information on barycentric coordinates, see Wikipedia

Assumes:: 1) points are given as numpy arrays (crashes if not met)

Parameters :

p :

point in space, or a list of points in space

p1,p2,p3 :

points space representing triangle (can be lists)

Returns :

[lambda1,lambda2,lambda3] :

the barycentric coordinates of point p with respect to the defined triangle

Examples

>>> [p,p1,p2,p3] = np.array([[0.5,0.5, 0],
...                          [  0,  0, 0],
...                          [  1,  0, 0],
...                          [  0,  1, 0]])
>>> barycentricCoordinates(p,p1,p2,p3)
array([ 0. ,  0.5,  0.5])

Will also work for arrays:

>>> p  = np.tile(p,(3,1));  p1 = np.tile(p1,(3,1))
>>> p2 = np.tile(p2,(3,1)); p3 = np.tile(p3,(3,1))
>>> barycentricCoordinates(p,p1,p2,p3)
array([[ 0. , 0.5, 0.5],
[ 0. , 0.5, 0.5], [ 0. , 0.5, 0.5]])

This Page