# tfg.math.interpolation.weighted.get_barycentric_coordinates

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/graphics/blob/master/tensorflow_graphics/math/interpolation/weighted.py#L97-L172) |

Computes the barycentric coordinates of pixels for 2D triangles.

    tfg.math.interpolation.weighted.get_barycentric_coordinates(
        triangle_vertices: type_alias.TensorLike,
        pixels: type_alias.TensorLike,
        name: str = 'rasterizer_get_barycentric_coordinates'
    ) -> type_alias.TensorLike

Barycentric coordinates of a point `p` are represented as coefficients
\\((w_1, w_2, w_3)\\) corresponding to the masses placed at the vertices of a
reference triangle if `p` is the center of mass. Barycentric coordinates are
normalized so that \\(w_1 + w_2 + w_3 = 1\\). These coordinates play an essential
role in computing the pixel attributes (e.g. depth, color, normals, and
texture coordinates) of a point lying on the surface of a triangle. The point
`p` is inside the triangle if all of its barycentric coordinates are positive.

<br />

<br />

<br />

| ## Note ||
|---|---|
| In the following, A1 to An are optional batch dimensions. ||

<br />

<br />

<br />

<br />

| ## Args ||
|---|---|
| `triangle_vertices` | A tensor of shape `[A1, ..., An, 3, 2]`, where the last two dimensions represents the `x` and `y` coordinates for each vertex of a 2D triangle. |
| `pixels` | A tensor of shape `[A1, ..., An, N, 2]`, where `N` represents the number of pixels, and the last dimension represents the `x` and `y` coordinates of each pixel. |
| `name` | A name for this op that defaults to "rasterizer_get_barycentric_coordinates". |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| `barycentric_coordinates` | A float tensor of shape `[A1, ..., An, N, 3]`, representing the barycentric coordinates. |
| `valid` | A boolean tensor of shape `[A1, ..., An, N], which is`True`where pixels are inside the triangle, and`False\` otherwise. |

<br />