Find point in a Triangle With UV coordinate
in
Programming Questions
•
1 year ago
Hi,
I' m trying to to find the UV coordinate from a point in a triangle and apply this coordinate in a other triangle.
To find the uv coordinate I' have adapted the code from this Websyte
Barycentric Technique (at the bottom).
the sketch to find UV from a point P:
- PVector v0;
- PVector v1;
- PVector v2;
- float invDenom;
- float dot00;
- float dot01;
- float dot02;
- float dot11;
- float dot12;
- //triangle Vector
- PVector A = new PVector(0, 0);
- PVector B = new PVector(0, 100);
- PVector C = new PVector(100, 100);
- //point to translate in uv
- PVector P = new PVector(10, 30);
- void setup() {
- size(130, 130);
- Calc();
- }
- void Calc(){
- float u;
- float v;
- v0 = PVector.sub(C, A);
- v1 = PVector.sub(B, A);
- v2 = PVector.sub(P, A);
- dot00 = v0.dot(v0);
- dot01 = v0.dot(v1);
- dot02 = v0.dot(v2);
- dot11 = v1.dot(v1);
- dot12 = v1.dot(v2);
- invDenom = 1 / (dot00 * dot11 - dot01 * dot01);
- u = (dot11 * dot02 - dot01 * dot12) * invDenom;
- v = (dot00 * dot12 - dot01 * dot02) * invDenom;
- print(" V="+v+" U="+u);
- }
- void draw() {
- line(A.x, A.y, B.x,B.y);
- line(B.x, B.y, C.x,C.y);
- line(A.x, A.y, C.x,C.y);
- ellipse(P.x, P.y, 3, 3);
- }
This code works but Now I would apply this UV coordinate in a Other triangle and find a new P point.
I have this equation. She comes from the websyte
Barycentric Technique. (at the bottom);
P = A + u * (C - A) + v * (B - A)
But I don't know how to add the PVector "A" with the float u.
Does anyone could help me to transform this equation in processing ?
Thank you and sorry for my poor English
Dodjix
1