I find a good website that teach me how to compute a barycentric coordinate of point P in the triangle T(v0,v1,v2). The formula can also be used to find is whether the P is inside T, which is the problem i want to solve.
Here is the link to the full explanation.
In short, the formula is like this:
u = V1-V0;
v = V2-V0;
w = P-V0;
The parametric coordinates (s,t) of P is the solution of the equation: w = su + tv, and the barycentric coordinates of P = b0V0 + b1V1 + b2V2 are equal to: b0 = (1-s-t), b1 = s, and b2 = t which satisfy: b0 + b1 + b2 = 1.
We can compute the solutions for s and t using only dot products as:
Thanks very much to Dan Sunday at http://softsurfer.com/index.html for providing the solution.
No comments:
Post a Comment