# How to map square texture to triangle?

I want to find the texture coordinates for point P. I have the vertices of the triangle and their corresponding uv coordinates.

The numbers in the little squares in the texture represent color values.

What are the steps of computing the uv coordinates of P?

You need to convert the point into barycentric coordinates and then use those points to interpolate the u, v coordinates.

Here is a previous answer that can help calculate the coordinates: What's the most efficient way to find barycentric coordinates?

With the barycentric coordinates, you then interpolate the UVs and get a weighted sum of the three vertices:

If your barycentric coordinates are defined as u,v,w then using the following equation (once for uv.X and once for uv.Y):

Point.UV.x = u * P0.uv.x + v * P1.uv.x + w * P2.uv.x
Point.UV.y = u * P0.uv.y + v * P1.uv.y + w * P2.uv.y


This works to linearly interpolate any property of each vertex across the triangle. Beware that interpolating normals linearly doesn't do what you want it to do as the normal becomes denormalized. This isn't an issue in your case.

• i found the barymetric coordinates. Now what points should I interpolate and what kind of interpolation do you mean ? – john john Jan 5 '16 at 17:31
• @johnjohn You need to interpolate. There's a question and answer over on Math SE about how to do this. Steven also included the code in his answer. – Draco18s Jan 5 '16 at 20:12
• @johnjohn I've updated the answer to include the interpolation code. – Steven Jan 5 '16 at 20:47