Relation between two 3D vectors that are in the same plane, to translate to 2D

Hello,

I’ve never asked a question on here or any other answering site but this has been bugging me for days and I’m sure there must be an easy answer to it.

  • I have two 3D unit (normalised) direction vectors D1 and D2 (so they go from point 0,0,0 in some direction).
  • Both D1 and D2 lie in the same plane (so there is a particular view in which if you look at the direction vectors from this point they will appear to look like one vector).
  • I have another unit direction vector, this time in 2D called T1.
  • I want the 2D unit direction vector T2 that is some rotation round from T1.
  • Going back to the 3D direction vectors, they share a normal because they are in the same plane. If I look at the 3D vectors from a point along this normal then in 2D T2 should be at a rotation from T1 that is the same as from D2 to D1.

Thank you!

I’ve drawn this too:

Well, if you just want to copy the angle between 3D unit vectors to 2D vectors, the job is easier. A possible solution is to calculate sin and cos from the 3D vectors, and use them to position the 2D vector. Since the vectors D1 and D2 are normalized (unit length), the ubiquitous Dot and Cross products can do the job: Dot(D1, D2) returns the cosine, and Cross(D1, D2) return a vector normal to D1 and D2 whose length is the sine of the angle. Putting all stuff together:

...
var sin: float = Vector3.Cross(D1, D2).magnitude; // calculate sine...
var cos: float = Vector3.Dot(D1, D2); // and cosine of the angle between D1,D2
// create a copy of T1 rotated 90 degrees clockwise:
var T1Right: Vector2 = Vector2(T1.y, -T1.x);
// now calculate T2 = T1 rotated by the same angle as D2:
T2 = T1 * cos + T1Right * sin;

This works fine if D1 and D2 are unit vectors, and T2 results the same size as T1.

NOTE: From your original question, I thought you were trying to map some point inside a mesh triangle to its equivalent in uv coordinates - if so, this may only work for plane surfaces: the mesh triangles in curved areas frequently have shapes different from the ones found in the uv map. If this is the case, you should instead interpolate the uv values according to the desired point - this article gives some hints about triangle interpolation.

So let us say that you have AB, which consists of the vectors/points A and B.
And you have F which consists of the vectors/points F1 and F2.

What you have is A, B, At, Bt, F1 and F2. What you need to find ist F1t and F2t. Let us ignore that the t vectors are in 2D, we could just set one coordinate to zero.

Then there is a transformation matrix that will transform A → At, B → Bt, F1 → F1t, F2 → F2t. If you can derive the matrix from AB and AtBt, then you could easily transform F??

Are the tex coords chosen manually by you or an artist? Then maybe you can find a way to formalize the transformation in to the matrix??

Maybe there is a much easier way to think about it. :smiley:

Judging by your picture and the description, it seems that you just need the angle between D1 and D2. float alpha = Vector3.angle(D1, D2);

Then you take your T1 and rotate it by alpha. Vector2 T2 = new Vector2(T1.x * Mathf.Cos(alpha), T1.y * Mathf.Sin(alpha));

No?

The real answer to my question and indeed a much much better explanation can be found here:

:slight_smile: