• Advertisement
Sign in to follow this  

Translate Mesh Point to Texture Point in Adjacent Triangle

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

Hello, and thank you for reading this!
 
I am trying to solve a problem with an application I'm developing and I need to ask for help from the community.  The short description is: I have two triangles on a mesh with vertices (A, B, C) and (B, D, C).  I have a point inside the first triangle (P), and this point describes the center of a circle having radius r.  A portion of the circle overlaps the second triangle.  See the figure below:
[attachment=30292:CG Texture Problem - composite.jpg]
 
Now we move to the texture space for that given mesh.  The first triangle maps to some region in the texture with UV coordinates A', B', and C'... like this:
[attachment=30293:CG Texture Problem - triangle 1.jpg]
 
In this image, the point P has been translated to P' in the texture map.  I believe I can use a couple of relatively simple calculations (barycentric coordinates, distance from a point) to determine if a given texel is within my desired radius from P'.
 
The second triangle maps to a different region of the texture with UV coordinates B", D", and C"... like this:
[attachment=30294:CG Texture Problem - triangle 2.jpg]
 
I believe I can use the same relatively simple calculations (barycentric coordinates, distance from a point) to determine if a given texel is within my desired radius from P".  
 
My challenge, though, is: How do I calculate the location of P" on the texture map relative to B" and C"?  The location of P" is the unknown for which I need a solution.
 
I hope this makes sense.  I've got 25+ years of programming experience, but only about 2-3 months of experience working with meshes and textures (even the concept of "barycentric" is still a bit shaky just yet, and things like "dot product" and "cross product" are stored in brain cells that haven't been dusted off in a couple of decades).  I know it's possible... I just don't know how.
 
Can anyone help me figure this out?
 
THANKS!
 

Share this post


Link to post
Share on other sites
Advertisement

i think the solution is

 

i assume A,B,C have texcoords

 

project P on face that is made by A,B,C

now B is your initial point

 

 

BA vector is your translation vector  say its called tba = ATexcoord - BTexcoord;

 

BC -> tbc = CTexcoord - BTexcoord;

 

project P onto BA and get the percentage of the length (projectedP from B) to BA length - tbx -> length(B, Projected(P)_onBA)  /  length(B,A)

same for BC and projected P onto it - tby

 

 

looks like PTexcoord = BTexCoord + (tbx*tba) + (tby*tbc);

 

im not 100% sure if that will work, but it seems so ph34r.png

Edited by WiredCat

Share this post


Link to post
Share on other sites

 I believe I can use a couple of relatively simple calculations (barycentric coordinates, distance from a point) to determine if a given texel is within my desired radius from P'.

 

Yes, the only issue is that the circle around P may be not be a circle in UV space due to possible stretch in the UV map, so it's best to do the distance test in mesh space.

 

Find the barycentric coordinates of a texel position in B'D'C' (in uv space) - use these to determine the texel's position in BDC.

 

Compare distance from this point to P to the length of the radius of the circle around P.

Edited by eppo

Share this post


Link to post
Share on other sites

Thank you for the pointers/solutions.  Had I considered that the points BCP make a triangle, I could have probably worked it through... but that's where I needed experience from you guys... to see things in a different way.  Thank you!

Share this post


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

  • Advertisement