0

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?

enter image description here

john john
  • 199
  • 1
  • 1
  • 7
  • 1
    Doublepost and answered:http://computergraphics.stackexchange.com/questions/1866/how-to-map-square-texture-to-triangle – Kromster Jan 05 '16 at 20:15

1 Answers1

1

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.

Steven
  • 3,062
  • 16
  • 24