# UV coords to 3D world position

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

## Recommended Posts

Hi, I'm doing stuff with lightMaps, and now I need to calculate a 3D world position. Given info is: - UV coordinates - The polygon where it belongs to - Polygon normal - 3 Polygon vertices (world positions) - The 3 UV coordates of those vertices So, I need a function something like this:
vector3f  UV_To_WorldPos( const float    u,v
const vector3f v1,v2,v3 // vertices
const vector2f t1,t2,t3 // vertex UV's
const vector3f normal );
{
...
}

Eventually I can also give the axis what was used for mapping the polygon (XY, XZ or YZ). But I'm not sure if that's correct... the UV coordinates are generated by another program, so I'm not sure if I use the right axis. I've read a few descriptions, but my math is not very good, and my technical english neither. Sorry! Greetings, Rick

##### Share on other sites
Well, I've gotten a bit rusty so there's most likely a much better way, but just to give a way...

Picture plotting the triangle in 2D using the UV coordinates then plotting the point on that triangle. You can then draw a line parallel to one axis through that point, say the U axis. That will intersect two sides. You don't know the V coordinate for those intersection points, but you know the U coordinate because it's the same as the point. You can use the U coordinate to find the percentage of the way along each edge and that percentage can be used to find the V coordinate. That percentage can also be used to find the 3D coordinates of those two points. The V coordinate of the point can then be used to find the percentage of the way between the two intersection points to the point of interest and that can be used to find the 3D coordintes of the point.

That's a bit of a brute force approach, but I'm a bit too rusty to provide a more elegant solution and suspect, even if I wasn't, the explaination of a more elegant solution wouldn't sound too elegant.

##### Share on other sites
Barycentric coordinates... that was exactly the thing I need! It works now, thanks!

Rick

1. 1
Rutin
39
2. 2
3. 3
4. 4
5. 5

• 12
• 16
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633357
• Total Posts
3011503
• ### Who's Online (See full list)

There are no registered users currently online

×