def barycentric_to_cartesian(tri, bc):
bc = np.asarray(bc)<EOL>tri = np.asarray(tri)<EOL>if len(bc.shape) == <NUM_LIT:1>:<EOL><INDENT>return barycentric_to_cartesian(np.transpose(np.asarray([tri]), (<NUM_LIT:1>,<NUM_LIT:2>,<NUM_LIT:0>)),<EOL>np.asarray([bc]).T)[:,<NUM_LIT:0>]<EOL><DEDENT>bc = bc if bc.shape[<NUM_LIT:0>] == <NUM_LIT:2> else bc.T<EOL>if bc.shape[<NUM_LIT:0>] != <NUM_LIT:2>: raise ValueError('<STR_LIT>')<EOL>n = bc.shape[<NUM_LIT:1>]<EOL>if len(tri.shape) == <NUM_LIT:2>:<EOL><INDENT>tri = np.transpose([tri for _ in range(n)], (<NUM_LIT:1>,<NUM_LIT:2>,<NUM_LIT:0>))<EOL><DEDENT>if tri.shape[<NUM_LIT:0>] == <NUM_LIT:3>:<EOL><INDENT>if tri.shape[<NUM_LIT:1>] in [<NUM_LIT:2>,<NUM_LIT:3>] and tri.shape[<NUM_LIT:2>] == n:<EOL><INDENT>pass <EOL><DEDENT>elif tri.shape[<NUM_LIT:1>] == n and tri.shape[<NUM_LIT:2>] in [<NUM_LIT:2>,<NUM_LIT:3>]:<EOL><INDENT>tri = np.transpose(tri, (<NUM_LIT:0>,<NUM_LIT:2>,<NUM_LIT:1>))<EOL><DEDENT>else: raise ValueError('<STR_LIT>')<EOL><DEDENT>elif tri.shape[<NUM_LIT:1>] == <NUM_LIT:3>:<EOL><INDENT>if tri.shape[<NUM_LIT:0>] in [<NUM_LIT:2>,<NUM_LIT:3>] and tri.shape[<NUM_LIT:2>] == n:<EOL><INDENT>tri = np.transpose(tri, (<NUM_LIT:1>,<NUM_LIT:0>,<NUM_LIT:2>))<EOL><DEDENT>elif tri.shape[<NUM_LIT:0>] == n and tri.shape[<NUM_LIT:2>] in [<NUM_LIT:2>,<NUM_LIT:3>]:<EOL><INDENT>tri = np.transpose(tri, (<NUM_LIT:1>,<NUM_LIT:2>,<NUM_LIT:0>))<EOL><DEDENT>else: raise ValueError('<STR_LIT>')<EOL><DEDENT>elif tri.shape[<NUM_LIT:2>] == <NUM_LIT:3>:<EOL><INDENT>if tri.shape[<NUM_LIT:0>] in [<NUM_LIT:2>,<NUM_LIT:3>] and tri.shape[<NUM_LIT:1>] == n:<EOL><INDENT>tri = np.transpose(tri, (<NUM_LIT:2>,<NUM_LIT:0>,<NUM_LIT:1>))<EOL><DEDENT>elif tri.shape[<NUM_LIT:0>] == n and tri.shape[<NUM_LIT:1>] in [<NUM_LIT:2>,<NUM_LIT:3>]:<EOL><INDENT>tri = np.transpose(tri, (<NUM_LIT:2>,<NUM_LIT:1>,<NUM_LIT:0>))<EOL><DEDENT>else: raise ValueError('<STR_LIT>')<EOL><DEDENT>else: raise ValueError('<STR_LIT>')<EOL>if tri.shape[<NUM_LIT:0>] != <NUM_LIT:3> or (tri.shape[<NUM_LIT:1>] not in [<NUM_LIT:2>,<NUM_LIT:3>]):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if tri.shape[<NUM_LIT:2>] != n:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>(l1,l2) = bc<EOL>(p1, p2, p3) = tri<EOL>l3 = (<NUM_LIT:1> - l1 - l2)<EOL>return np.asarray([x1*l1 + x2*l2 + x3*l3 for (x1,x2,x3) in zip(p1, p2, p3)])<EOL>
barycentric_to_cartesian(tri, bc) yields the d x n coordinate matrix of the given barycentric
coordinate matrix (also d x n) bc interpolated in the n triangles given in the array tri. See
also cartesian_to_barycentric. If tri and bc represent one triangle and coordinate, then just
the coordinate and not a matrix is returned. The value d, dimensions, must be 2 or 3.