I was reading up about Bezier triangles in the hopes of running some experiments, but my understanding of math terminology is not keeping up. According to this article:
You can interpolate positions on a triangular surface with some number of control points with this formula
You can also determine the tangent frame at that point with the two partial derivatives:
The problem I am having is that I just can't figure out how to write this out in long form. The sigma operator always defeats any chance I have of math comprehension. I have seen 3rd order triangles written out in the case of PN-triangles etc. but I can't make out the pattern of iteration enough to expand it to higher orders. I don't even understand how and why the big 'B' is different than the bold 'p'. My experiment is going to be using a 6th order Bezier triangle (7 control points on each side) So if I have all the 28 control points set and I want to know the position at the barycentric coords p(u,v) how to I calculate that with code? I need the same help with the two partial derivatives as well.
Ok, here are the results that I calculated. Hopefully there aren't too many mistakes. First I will calculate w so that the patterns can be more easily seen for calculating the position at (u,v):
w = 1 - u - v; p(u,v) = p600 * u^6 + p060 * v^6 + p006 * w^6 + p501 * 6 * u^5 * w + p510 * 6 * u^5 * v + p150 * 6 * u * v^5 + p051 * 6 * v^5 * w + p105 * 6 * u * w^5 + p015 * 6 * v * w^5 + p402 * 15 * u^4 * w^2 + p411 * 30 * u^4 * v * w + p420 * 15 * u^4 * w^2 + p240 * 15 * u^2 * v^4 + p141 * 30 * u * v^4 * w + p042 * 15 * v^4 * w^2 + p024 * 15 * v^2 * w^4 + p114 * 30 * u * v * w^4 + p204 * 15 * u^2 * w^4 + p303 * 20 * u^3 * w^3 + p312 * 60 * u^3 * v * w^2 + p321 * 60 * u^3 * v^2 * w + p330 * 20 * u^3 * v^3 + p231 * 60 * u^2 * v^3 * w + p132 * 60 * u * v^3 * w^2 + p033 * 20 * v^3 * w^3 + p213 * 60 * u^2 * v * w^3 + p123 * 60 * u * v^2 * w^3 + p222 * 90 * u^2 * v^2 * w^2;
Now for the partial derivatives. This is a little more complicated to understand, because you calculate these with a subset of control points that is basically a bezier triangle at an order that is one smaller, such that you are leaving off the opposite edge of the original triangle. Mapping this smaller triangle onto the original control points looks a bit strange, hopefully I did it correctly:
partial derivative for u dp(u,v)/du = p600 * u^5 + p501 * 5 * u^4 * w + p510 * 5 * u^4 * v + p402 * 10 * u^3 * w^2 + p411 * 20 * u^3 * v * w + p420 * 10 * u^3 * v^2 + p303 * 10 * u^2 * w^3 + p312 * 30 * u^2 * v * w^2 + p321 * 30 * u^2 * v^2 * w + p330 * 10 * u^2 * v^3 + p204 * 5 * u * w^4 + p213 * 20 * u * v * w^3 + p222 * 30 * u * v^2 * w^2 + p231 * 20 * u * v^3 * w + p240 * 5 * u * v^4 + p105 * w^5 + p114 * 5 * v * w^4 + p123 * 10 * v^2 * w^3 + p132 * 10 * v^3 * w^2 + p141 * 5 * v^4 * w + p150 * v^5; partial derivative for v dp(u,v)/dv = p060 * v^5 + p150 * 5 * u * v^4 + p051 * 5 * v^4 * w + p240 * 10 * u^2 * v^3 + p141 * 20 * u * v^3 * w + p042 * 10 * v^3 * w^2 + p330 * 10 * u^3 * v^2 + p231 * 30 * u^2 * v^2 * w + p132 * 30 * u * v^2 * w^2 + p033 * 10 * v^2 * w^3 + p420 * 5 * u^4 * v + p321 * 20 * u^3 * v * w + p222 * 30 * u^2 * v * w^2 + p123 * 20 * u * v * w^3 + p024 * 5 * v * w^4 + p510 * u^5 + p411 * 5 * u^4 * w + p312 * 10 * u^3 * w^2 + p213 * 10 * u^2 * w^3 + p114 * 5 * u * w^4 + p015 * w^5;
I would guess if you were going to use these tangents for a tangent frame in a shader, you might have to fiddle with them a bit since they are calculated from barycentric coordinates and are probably not perpendicular on the plane. Perhaps you could calculate the normal, then create a new bitangent from the normal and tangent, and then rotate it to your texture edge somehow.