# Solving UV for different vertices (understanding a formula)

This topic is 1159 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all,
I'm struggling a bit with an exercise I'm trying to do.
Here's the statement in my book:

"Let p0, p1, p2 be the vertices of a 3D Triangle with respective tex coords q0, q1 and 2.
For an arbitrary point on a 3D triangle P(s,t) = p0 + s(q1 - q0) + t(q2 - q0), where s >= 0, t >=0 and t <= 1, it's texture coordinates (u,v) are found by linearly interpolating the vertex texture coordinates across the 3D triangle by the same s, t parameters:

(u, v) = q0 + s(q1 - q0) + t(q2 - q0)"

Reading this, I understand that you can calculate the UV coordinates of a pixel/ point on a triangle, if you know the 3 UV coordinates of the 3 vertices of the triangle. Funtionally, I understand this. But the formula doesn't really make sense to me yet.

I've drawn this just for illustration:

Say I now the UV coordinates of p0,p1,p2, being q0, q1 and q2.
Then the formula states you can calculate the UV coordinates at the point 'p'.

For example:
p0 = -1, -1, 0
p1 = 0, 0, 0
p2 = 1, -1, 0

q0 = 0, 1.0
q1 = 0.5, 0.0
q2 = 1.0, 1.0

And p = 0, -0.5, 0

Then apply the formula:
(u, v) = q0 + s(q1 - q0) + t(q2 - q0)

I have no s and no t, maybe a stupid question, but how do I apply the formula?

That's my first question.
After I figure this out, I might also want to ask some help on the follow up questions:

a. Given (u,v) and q0, q1, q2, solve for (s,t) in terms of u and v
(sounds like 'shuffling' the formula above, where I have 5 known and 2 unknowns)
b. Express 'p' as a function of u and v; find a formula p = p (u,v)
c. Compute vectors .p/.u and .p/.v and give a geometric interpretation of what these vectors mean
(I could maybe draw these on the sample drawing above)

Just to be sure, I'm not looking for the end resulting answers, just trying to learn and understand (also how to get to the answer).
Any help is appreciated.

##### Share on other sites

For an arbitrary point on a 3D triangle P(s,t) = p0 + s(q1 - q0) + t(q2 - q0), [...]

You probably meant P(s,t) = p0 + s(p1 - p0) + t(p2 - p0)'.

In your example, (0,0,0) is not in the triangle with vertices (-1,-1,0), (1,0,0) and (1,-1,0), so the situation doesn't look at all like the one in your diagram.

If you set up the problem P(s,t)=(0,0,0) you can turn that into a system of 2 linear equations with 2 unknowns, whose solution is s=-1, t=-2/3 (unless I made a mistake somewhere). Edited by Álvaro

##### Share on other sites

s and t are the barycentric coordinates of p with respect to the triangle.

If you only know p0, p1, p2 and p, you can derive s and t by comparing the area of the triangles s:{ p, p2, p0 } and t:{ p, p0, p1 } to the area of the entire triangle.

##### Share on other sites
Thanks. I'm afraid I'm not getting it yet.
I've changed the example vertices and UV's to match the drawing example.

I thought the formula would give me a way to calculate the UV coordinates for point p, knowing p1/2/3 and uv's q1/2/3.

How can I do that with this formula? (step by step)

Should I read baryentric coordinates of p to respect of the triangle, as the same thing?

##### Share on other sites

I've changed the example vertices and UV's to match the drawing example.

Man, don't do that! Now someone that comes and tries to read the thread as a conversation will think my comment makes no sense.

Anyway, here it goes:

p0 = (-1, -1, 0)
p1 = (0, 0, 0)
p2 = (1, -1, 0)
p = (0, -0.5, 0)

I am trying to write p = p0 + s(p1 - p0) + t(p2 - p0) (again, the formula in your post involves q0, q1 and q2, but that doesn't make sense).

(0, -0.5, 0) = (-1, -1, 0) + s(1, 1, 0) + t(2, 0, 0)

(0, -0.5, 0) = (-1 + s + 2*t, -1 + s, 0)

So the first coordinates being equal means -1 + s + 2*t = 0, and the second coordinates being equal means -1 + s = -0.5

So now we have a system of equations:
s + 2 * t = 1
s = 0.5

Well, s is already solved for in the second equation, so we substitute in the first equation and we get 0.5 + 2 * t = 1, so t = 0.25.

There you have it, s = 0.5 and t = 0.25 in your new example. Now you can use those values to interpolate between the q's and get your (u,v) coordinates at p.

##### Share on other sites

s and t are the barycentric coordinates of p with respect to the triangle.

If you only know p0, p1, p2 and p, you can derive s and t by comparing the area of the triangles s:{ p, p2, p0 } and t:{ p, p0, p1 } to the area of the entire triangle.

I don't really know too much about barycentric coords, but are they not still a triplet?

@cozzie Alvaro has steered you right. You way want to check out tangent space calculations, as that's where i've seen s and t used before. the c4 engine site has a good whitepaper on it.

##### Share on other sites

s and t are the barycentric coordinates of p with respect to the triangle.

If you only know p0, p1, p2 and p, you can derive s and t by comparing the area of the triangles s:{ p, p2, p0 } and t:{ p, p0, p1 } to the area of the entire triangle.

I don't really know too much about barycentric coords, but are they not still a triplet?

Yes, barycentric coordinates are a triplet. Coordinates like s and t are called affine coordinates. When I studied this in college (in Spain), we referred to the points p1, p2, p3 as an "affine reference", but searching the web it doesn't seem like it's a popular term.

The triplet (1-s-t, s, t) are actual barycentric coordinates, so it doesn't seem too wrong to describe (s,t) that way.

##### Share on other sites

s and t are the barycentric coordinates of p with respect to the triangle.

If you only know p0, p1, p2 and p, you can derive s and t by comparing the area of the triangles s:{ p, p2, p0 } and t:{ p, p0, p1 } to the area of the entire triangle.

I don't really know too much about barycentric coords, but are they not still a triplet?

Yes, barycentric coordinates are a triplet. Coordinates like s and t are called affine coordinates. When I studied this in college (in Spain), we referred to the points p1, p2, p3 as an "affine reference", but searching the web it doesn't seem like it's a popular term.

The triplet (1-s-t, s, t) are actual barycentric coordinates, so it doesn't seem too wrong to describe (s,t) that way.

Thanks for the clarification :)

##### Share on other sites

Hey guys. sorry for the late response and reactions.

I tried to recap for my own understanding:

p = p0 + s(p1 - p0) + t(p2 - p0)

brings us to:

(0, -0.5, 0) = (-1, -1, 0) + s(1, 1, 0) + t(2, 0, 0)

Then I add up the individual components, like this:

-1 + 1s + 2t = -1 + s + 2*t

-1 + (1)s + 0" = -1 + s

0 + 0s + 0t = 0

Bringing us to:

(0, -0.5, 0) = (-1 + s + 2*t, -1 + s, 0)

How do I go from A to "s + 2 * t = 1", simply adding 1 to both side of the equations: 1 = s + 2 * t?

If so, I understand that:

s + 2 * t = 1

-1 + s = -0.5

Then s = -0.5 - -1 = 0.5

For t: 0.5 + 2 * t = 1

2 * t = 1 - 0.5

2 * t = 0.5

t = 0.25

All done and OK?

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633701
• Total Posts
3013444
×