I'm working on some computer graphic stuff and can't figure out solution to one problem:
I have three points in 3D space, each defined with (x,y,z) tupple. Three points together form a triangle. Let point names be A, B and C, so triangle is ABC.
Now I'd like to form a bounding rectangle such that AC is one of the sides. and point B lies on the opposide side of the rectangle. Now I want to map an arbitrary point (p) within the rectangle to normalized UV coordinates, so:
- U represents how far projection of the point p to AC vector is from A.
- V represents the orthogonal part of the rectangle. A bit hard to explain, but see the picture.
Anyway, I think I'm good with finding U:
vec3 AC = vec3(C - A);
vec3 Ap = vec3(p - A);
float u = dot(Ap, AC)/dot(AC, AC);
But I can't figure out how to find V. As I use GLSL, it's more than welcome if the answer will use matrix thingies like dot, cross or anything GLSL has.

triaNorm = cross(AC, AB); acNorm = cross(-triaNorm, AC); bProj = acNorm * dot(acNorm, B) / dot(acNorm, acNorm); u = dot(Ap, AC) / dot(AC, AC); v = dot(Ap, bProj) / dot(AC, AC);One thing left unclear was what vectors needed to be normalized. One suspicious vector was bProj, because whether normalization was on or off for this vector was giving the different results.
– lhog Jun 05 '18 at 07:42Uwithout any question doesn't need to be normalized as per your latest comment. I have my doubts about the vectors that eventually help defineV, specificallybProjwhich is supposed to be the projection of pointBonto normal toAC(coplanar to triangle plane). Also see: https://stackoverflow.com/questions/50688334/complete-tesselation-of-sphere-with-hexagons where I used the transformations above, but faced another issue. – lhog Jun 05 '18 at 18:10