Jump to content
• Advertisement

# How to get UV coordinates for a point inside triangle

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

If you intended to correct an error in the post then please contact us.

## Recommended Posts

Hi I have a triangle in 3d space(p1,p2,p3) and a point (p) inside it and UV coordinates at the 3 corners of the triangle (UV1, UV2, UV3). I want to get the UV coordinates for point (p). input : 3d vectors : p1 ,p2 ,p3 ,p 2d vectors : UV1 ,UV2 ,UV3 output: 2d vector : UV Thanks

#### Share this post

##### Share on other sites
Advertisement
Find the barycentric coordinates of the point inside your triangle. There's lots of ways to do this, try googling around. One way is to take the ratios of the signed areas of the triangles: {P, P2, P3}, {P1, P, P3}, {P1, P2, P} and the signed area of the original triangle: {P1, P2, P3}. {P, P2, P3} / {P1, P2, P3} = relative weight of point P1. Likewise for the other two.

Once you have the barycentric weights of the triangle needed to form your point, apply them to the UV coordinates. ie: UV1 * (weight of P1) + UV2 * (weight of P2) + UV3 * (weight of P3). That will give you the UV of the point.

Also note that if you're using a pixel shader, the hardware will automatically do this for you and feed teh particle shader the proper UV coords.

#### Share this post

##### Share on other sites
Thanks a lot Numsgil !

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5
• Advertisement

• 14
• 10
• 23
• 9
• 32
• ### Forum Statistics

• Total Topics
632630
• Total Posts
3007525
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!