alecjacobson / gptoolbox

Matlab toolbox for Geometry Processing.
MIT License
628 stars 166 forks source link

a little question about grad() #53

Open seamanj opened 6 years ago

seamanj commented 6 years ago

Hi, Alec

Nice to see again here. Here is my situation, I want to use grad to compute the gradient on each vertices of a mesh, but I found the grad() function solving the gradient on each faces only. So my question is:

how do we compute the gradient on each vertex? Do you think it is reasonable if we just accumulate the gradient of each triangle which connected to that vertex to get the result?

Many thanks Tao

alecjacobson commented 6 years ago

Grad (and most of the other functions in gptoolbox) are assuming that functions on triangle meshes are piecewise-linear: they are defined as linear functions in each triangle, interpolating prescribed values at vertices. Therefore their gradients are only well defined inside each triangle (where they are constant).

Nonetheless, sometimes it's useful to have gradient values at vertices. (I'll throw in one word of caution that in my experience this usually indicates a problem modelling issue that may creep up again in other ways).

Averaging incident face values is a common approach (I believe Ben-Chen et al. do this). It would probably be reasonable to use area-weighting or angle-weighting, like per_vertex_normals does for interpolating face normal vectors on to vertices.

seamanj commented 6 years ago

Thank you very much for your reply.

I will take further investigate into the per_vertex_normals function. However, you mentioned Ben-Chen et al.'s work, could u tell me their specific reference or work? Much appreciated for that!

Best Tao