# UV coords within triangle

I have a textured triangle that I’m trying to subdivide, but I’m not sure how to calculate the UV coordinates for the smaller triangles. I’ve googled around and it seems like I need to use barycentric coordinates for this, but I don’t understand how they would work in this situation.

Can’t I just create a 2D triangle out of the 3 sets of UV coordinates and subdivide that alongside the actual triangle (using position data from that imaginary triangle as UV data for the real one)?

How exactly are you subdividing? What’s the tesselation math?

I split the triangle up into n amount of rows, and then go through each row and fill it with triangles.

The end product looks something like this:
http://phrogz.net/CSS/Geodesics/imgs/base.gif

There are multiple ways to determine the coordinates of a point inside a triangle. Barycentric coordinates are one of them. For the simple case above one could come up with a relatively simple solution. But this won’t do you any good as soon as the tesselation algorithm and the base triangle changes. You should go for a general approach - like barycentric coordinates. It’s not that hard.

http://en.wikipedia.org/wiki/Barycentric_coordinate_system_(mathematics) shows it pretty straightforwardly. Write yourself a function which takes the three known vertices as inputs and spits out the barycentric coordinates lambda{1-3}. Then takes these coefficients and determine the uv-coordinate by

UV_P = lambda_1 * UV_P1 + lambda_2 * UV_P2 + lamda_3 * UV_P3

This should work.

Thanks! That formula worked surprisingly well. I had a little trouble at first because I didn’t know that the lambda values were supposed to be calculated from the triangle that the UV coordinates make up, and not the 3D position coordinates of triangle i’m subdividing.