per wiki, the conversion from barycentric coordinates to Cartesian coordinates is as follow
here is a piece of code come from somewhere else
import numpy as np
import matplotlib.pyplot as plt
# from barycentric coordinates to Cartesian coordinates
a = np.array([0. , 0. , 1. , 0.25, 0.25, 0.5 ])
b = np.array([0. , 1. , 0. , 0.25, 0.5 , 0.25])
c = np.array([1. , 0. , 0. , 0.5 , 0.25, 0.25])
x = 0.5 * ( 2.*b+c ) / ( a+b+c )
y = 0.5*np.sqrt(3) * c / (a+b+c)
plt.scatter(x,y)
plt.show()
it seems that the piece of code is using another formula, if it is, what is the formula?
assume the barycentric coordinates of B is (0,0,1), how to compute its Cartesian coordinates? what lambda_1, lambda_2, lambda_3, x_1, x_2, x_3, y_1, y_2, y_3 are for point B?
Your formula is correct.
Assuming that the three corners of a triangles are encoded as the columns of the matrix
t
, here is a simple Python implementation:The formula you found is also calculating Cartesian from barycentric coordinates but uses a predefined regular triangle with the following coordinates:
In this calculation, the code considers that every column is a point expressed with barycentric coordinates. Thus, it calculates 6 points at once. Furthermore, barycentric coordinates need to be normalized, i.e.,
lambda1 + lamda2 + lambda3 = 1
. This code does not assume normalization, so it needs to divide by the sum of lambdas to ensure this property. Of course, we can see that the sum is always 1 for all 6 points, but the code could be used for lambdas that do not sum to 1.In the last example you gave, B is a point of the triangle and is not expressed with barycentric coordinates. P is the point that is expressed with barycentric coordinate relative to the point A, B, and C. Let
A = (x1,y1)
,B = (x2,y2)
, andC = (x3,y3)
, and that P has barycentric coordinates(l1,l2,l3)
. Then, the Cartesian coordinates(xp,yp)
of P is