Parametrising $\mathbb{R^3}$ coordinates using a mesh with barycentric coordinates, and signed distance to the mesh I need to find a way to parametrise $\mathbb{R^3}$ coordinates relative to a mesh, which is a deformed $UV$ sphere with triangular faces. Every vertex on the mesh has a $UV$ coordinate, and I want to associate every $\mathbb{R^3}-$ point with a coordinate ($u,v$, signed distance). So for instance, points on the mesh would simply be assigned $(u,v,0)$. If a point starts on the mesh at a vertex and then moves outwards by $1$ in the direction of the vertex normal, the new point should be assigned $(u,v,1)$. If a point starts on the mesh inside a face, its normal is a barycentric combination of the surrounding vertex normals, then $(u,v,1)$ is defined as above. Moving inwards gives a negative signed distance. It seems intuitive to me that this formulation assigns a coordinate to every point in $\mathbb{R^3}$, since it is like inflating the mesh until you reach any arbitrary point in $\mathbb{R^3}$. However, I have not been able to find an efficient (or any) way to compute this on an arbitrary $\mathbb{R^3}$ point for a given set of vertex positions. Can anyone see such a way, or is there another approach which is easier altogether?
 A: This sounds like a computer graphics problem.
Suppose $P$ is the point you want to parametrize. Let $T$ be a triangle with vertices $x_1,x_2,x_3$, vertex normals $n_1,n_2,n_3$ and UV coordinates $u_1,u_2,u_3$. You want to find a point $X=ax_1+bx_2+(1-a-b)x_3$ with normal $N=an_1+bn_2+(1-a-b)n_3$ such that $N$ is parallel with the line $XP$.  This will be the case if the cross product $C=N\times(P-X)=0$.  The vector $C$ will have three components that are 2nd degree functions in $a$ and $b$ so you have to solve for $a$ and $b$.  This is essentially solving for the intersection of three conics.  Best to find an existing solver, but check out this question and answers: Algorithm: Intersection of two conics
Once you have this information, compute the signed distance $w$.  And $(u,v)=au_1+bu_2+(1-a-b)u_3$, so the parametrization of $P$ with respect to $T$ is $(u,v,w)$.
It remains to choose a triangle $T$.  Depending on how much the sphere is deformed, there may be more than one $(u,v,w)$ coordinate for a point.
But your best bet should be to choose the triangle closest to $P$.
