• Advertisement
Sign in to follow this  

How to get UV coordinates for a point inside triangle

This topic is 3187 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


Link to 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


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement