# How to find UV coordinate from a point on mesh

Hi everyone !

With the method closes_point_on_mesh(point,dist) , it’s return the closest point of the mesh from the coordinate you enter int the “point” argument , it’s normal and the polygon index of it.

From this data , it’s possible to find which UV coordinate ( of a specified UV set ) this point on mesh is referred to ?

I don’t know if my question is clear

thanks a lot

if the returned face index is != -1, get that face’s uvs and vertices:

me = bpy.context.object.data
face = me.polygons[face_index]
uvs = [me.uv_layers.active.data[li] for li in face.loop_indices]
verts = [me.vertices[v] for v in face.vertices]

uvs and verts should match (uv 1 = vert 1 etc.)

then interpolate the uv and vert data to find the uv coord at the calculcated point (not sure how to do this step)

Yes I think is the math for the latest point that scare me a bit No function in Blender already exist for that ? The first hint I get if I need to do it myself is about calculate the Barycentic … not sure but I start with that. Somebody know about this math ?

All i found in blender so far:
mathutils.geometry.barycentric_transform

bmesh geometry elements got a copy_from_face_interp() method, but there doesn’t seem to be an utility function for polygon interpolation…

We should deffo look at the C-code, as modifiers etc. support custom data interpolation!

Thanx for the help CoDEmanX ! It’s really help me !
I find a way but I need to triangulate the mesh before ( because barycentric just use corrdinate of 3 point ) and it’s make sure you don’t have any ngons face anyway.

I use store the position of point on polygon in P , position of 3 vertices of the polygons in A,B,C and position of corresponding UVs vertices in U,V,W

After that I use the code:

uvP = mathutils.geometry.barycentric_transform(P,A,B,C,U,V,W)

to store in uvP where the point is on the UVs.

Not sure I’m clear… but here is the result for my molecular addon: