cartesianToBarycentric
Converts Cartesian points to barycentric coordinates relative to given triangles or tetrahedra.
Category: Mathematics > Computational Geometry
Syntax
B = cartesianToBarycentric(TR, T, X)
Returns the barycentric coordinates of each row of X with respect to the simplex listed in T.
Description
Barycentric coordinates express a point as weights on the vertices of a simplex. To find them, the function solves a small linear system built from the simplex's vertices. The coordinates are all in [0, 1] exactly when the point lies inside the simplex, which makes this a convenient inside test and the base of linear interpolation over a mesh.
The query points do not have to lie inside the chosen simplex; they are then extrapolated.
Input arguments
TR- A
triangulationordelaunayTriangulation(2-D, 3-D tetrahedral or 3-D surface triangles). T- Column vector of simplex indices, one per query point.
X- Query points, one per row.
Output arguments
B- Barycentric coordinates, one row per query point. Rows sum to 1; a negative entry means the point lies outside that simplex.
Examples
Point outside the chosen triangle
x = [0 1 1 0 0.5]';
y = [0 0 1 1 0.5]';
DT = delaunayTriangulation(x, y);
B = cartesianToBarycentric(DT, 1, [0.1 0.2])
Output
B = 1×3
1.8000 -0.1000 -0.7000
Tetrahedron
tet = delaunayTriangulation([0 0 0; 1 0 0; 0 1 0; 0 0 1]);
B = cartesianToBarycentric(tet, 1, [0.1 0.1 0.1])
Output
B = 1×4
0.7000 0.1000 0.1000 0.1000