Sign in to follow this  
SNARG

Finding 3D co-ordinates of UV(1,1)?

Recommended Posts

Given 3 vertices in 3D space, each with a texture co-ordinate, how do you find the 3D co-ordinates of UV(1,1)(0,0)(1,0)and (0,1). Assuming the 3 texture co-ordinates are all different, < 1.0 and > 0.0. Sounds really simple until you try to work it out. :( Any help greatly appreciated.

Share this post


Link to post
Share on other sites
Form the matrices

[u1 u2 u3]
[v1 v2 v3] = U
[ 1 1 1]

and

[x1 x2 x3]
[y1 y2 y3] = X
[z1 z2 z3]

Then the point corresponding to a particular UV is given by X * inverse(U) * vec3(u,v,1). For example X * inverse(U) * vec3(1,1,1) is the point corresponding to a UV of (1,1).

[Edited by - Pragma on May 1, 2010 8:52:19 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Pragma
Form the matrices

[u1 u2 u3]
[v1 v2 v3] = U
[ 1 1 1]

and

[x1 x2 x3]
[y1 y2 y3] = X
[z1 z2 z3]

Then the point corresponding to a particular UV is given by X * inverse(U) * vec3(u,v,1). For example X * inverse(U) * vec3(1,1,1) is the point corresponding to a UV of (1,1).


What are u1,v1, u2,v2, u3,v3?
What are x1,y1,z1, x2,y2,z2, x3,y3,z3?

Share this post


Link to post
Share on other sites
He said he had 3 vertices in 3d space, each with a texture coordinate. So
(u1, v1) = texture coordinate of first vertex
(x1, y1, z1) = position of first vertex
(u2, v2) = texture coordinate of second vertex
... etc.

Share this post


Link to post
Share on other sites
Quote:
Original post by Pragma
He said he had 3 vertices in 3d space, each with a texture coordinate. So
(u1, v1) = texture coordinate of first vertex
(x1, y1, z1) = position of first vertex
(u2, v2) = texture coordinate of second vertex
... etc.


The xyz part is a matrix of a triangle? If you took the inverse of such a matrix, what exactly would that represent?

Share this post


Link to post
Share on other sites
Quote:
Original post by samster581
The xyz part is a matrix of a triangle? If you took the inverse of such a matrix, what exactly would that represent?


Yes, it's for a triangle, specifically to find the flat(or planar) projection of a UV textured triangle.

@Pragma 10 years since I did any matrix maths so taking a while to work out the equations, simplify them and test it with real numbers, thanks for the inverse of a matrix btw OMG :-D
Seriously, if this works, your a mega genius, how the hell did you figure out that solution? Guess it's knowing the power of matrices...

Share this post


Link to post
Share on other sites
Maybe it's easier just to think about it as a system of linear equations. Every point in the plane of the triangle can be written as a linear combination of the vertices with coefficients a,b,c that sum to one. Suppose this point has UV of (u,v) and coordinates (x,y,z). Then the equations it satisfies are:

u = a u1 + b u2 + c u3
v = a v1 + b v2 + c v3
1 = a + b + c

x = a x1 + b x2 + c x3
y = a y1 + b y2 + c y3
v = a z1 + b z2 + c z3

Now this starts to look like a pair of matrix equations. We can write them as

[u1 u2 u3] [a] [a] [u]
[v1 v2 v3] [b] = U [b] = [v]
[ 1 1 1] [c] [c] [1]

[x1 x2 x3] [a] [a] [x]
[y1 y2 y3] [b] = X [b] = [y]
[z1 z2 z3] [c] [c] [z]

This is where the matrices U and X came from. Now we can use the first matrix equation to solve for a, b and c as
 
[a] [u]
[b] = U^-1 [v]
[c] [1]

and plug this answer in to the second equation to get

[x] [a] [u]
[y] = X [b] = X * U^-1 [v]
[z] [c] [1]


[Edited by - Pragma on May 3, 2010 5:37:59 AM]

Share this post


Link to post
Share on other sites
Can't get it to work :(
Either i'm doing something fundamentally wrong, screwed up the inverse or it just doesn't work. Using a column vector, that's ok isn't it?

Some real data if you want to try it.
x,y,z -41.3953 -7.9605 -97.3297 uv(0.12500, 0.12500)
x,y,z 34.4961 -45.9345 27.6143 uv(0.81250 0.43750)
x,y,z -20.6976 39.8266 -4.0867 uv(0.31250 0.62500)

Share this post


Link to post
Share on other sites
Yes, everything should be a column vector. Maybe check your matrix inversion?

The method works fine for me. Here's some octave code I used to test it:

X = [ -41.3953, 34.4961, -20.6976;
-7.9605, -45.9345, 39.8266;
-97.3297, 27.6143, -4.0867];

U = [ 0.12500, 0.81250, 0.31250,
0.12500, 0.43750, 0.62500,
1.00000, 1.00000, 1.00000];

M = X * inverse(U);

M * [0.12500; 0.12500; 1]
M * [0.81250; 0.43750; 1]
M * [0.31250; 0.62500; 1]

And here's the output:

ans =

-41.3953
-7.9605
-97.3297

ans =

34.496
-45.934
27.614

ans =

-20.6976
39.8266
-4.0867

Share this post


Link to post
Share on other sites
Also if you want to compare to your code, the matrix I get is

M =

1.1039e+02 1.0959e-04 -5.5194e+01
-1.1895e+02 1.4018e+02 -1.0614e+01
1.1690e+02 1.4265e+02 -1.2977e+02

Share this post


Link to post
Share on other sites
That matrix is perfect.

vertex 4 {
-55.1937 -10.6140 -129.7729 ... for UV(0,0)
55.1937 -129.5679 -12.8772 ...for UV(1,0)
-55.1937 129.5679 12.8772 ...for UV(0,1) EDIT: got these 2
55.1937 10.6140 129.7729 ...for UV(1,1) UV's mixed up. Corrected.
}

Mistake was not applying the + - + matrix before the transpose. And did BxA instead of AxB.
REALLY BIG THANKS for that method and spending the time to go through explaining it and checking the answers.

Very very appreciated, not only by me but the hundreds of others who will be using it as well.

[Edited by - SNARG on May 9, 2010 11:32:03 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this