[vtkusers] vtkPolygon.cxx To do comment MVC angle computation

Andreas Schuh andreas.schuh.84 at gmail.com
Sat Jun 4 13:20:56 EDT 2016


I was recently implementing MVC based texture mapping and thereby introduced to the concept of mean value coordinates. Coincidentally, I found the vtkPolygon.cxx implementation of MVC interpolation for planar polygons. In the VTK source code, there is the following note:

 // Now loop over all vertices to compute weight
 // w_i = ( tan(theta_i/2) + tan(theta_(i+1)/2) ) / dist_i
 // To do consider the simplification of
 // tan(alpha/2) = (1-cos(alpha))/sin(alpha)
 //              = (d0*d1 - cross(u0, u1))/(2*dot(u0,u1))

where the needed weights are based on the actual computation of the angles and the expensive/numerically less robust use of trigonometric functions yet.

This note provides the needed identity for the tan(alpha/2) based on cos(alpha) and sin(alpha) only. However, the second line of the simplification is incorrect. I just thought I’d drop a note here for somebody to correct the comment to not mislead anyone how wants to actually implement it.

The correct formula uses the following relations between cos/sin and inner/outer vector products:

 cos(alpha) = dot(u0, u1) / (d0 * d1)
 sin(alpha) = norm(cross(u0, u1)) / (d0 * d1)

which when substituted into

 tan(alpha/2) = (1 - cos(alpha)) / sin(alpha)


 tan(alpha/2) = (d0 * d1 - dot(u0, u1)) / norm(cross(u0, u1))

instead of the above formula.


More information about the vtkusers mailing list