0
votes

EDITED:

I have a set of texture coordinates & Cartesian real-world ('world space') coordinates (in metres) for a shape and from those coordinates I'd like to find the world space length of a single unit of each of the s and t texture coordinates, when the line corresponding to that length is oriented horizontally & vertically respectively, in texture space. But I am struggling to calculate this when I don't have at least one edge which is oriented horizontally and one edge which is oriented vertically in texture space.

Essentially I would like to be able to find out what 1 s unit equals in metres and what 1 t unit equals in metres. To illustrate this, using an example triangle shape - see below for list of coordinate values - I want to find the length of the vertical & horizontal red arrowed lines in metres ...

(I'd also like the solution to work for any triangle or polygon, given the equivalent set of coordinates)

Essentially I want to find the length of the vertical & horizontal red arrowed lines in metres

Texture mapping here is non-parametric, all 3D points are also coplanar and hence the surface is developable. Mapping in world space on the plane is isometric (global scaling) such that interpolation in 2D can therefore be linear.

(as it is I'm working in MATLAB - I'm texture mapping and want to be able to convert any texture coordinate on my developable, globally-scaled surface to Cartesian coordinates)

By way of example I have triangle with a set of texture coordinates (s, t) as follows ...

EDITED VALUES (twice):

(1) 1.7942553649452966 0.8511551466745527
(2) 1.756240725743247 0.8674815156738774
(3) 1.730892921329496 0.8328561344213196
(1) 1.7942553649452966 0.8511551466745527

... which has corresponding real-world (Cartesian) coordinates (x, y, z) with units of metres ...

EDITED VALUES (twice):

(1) 660050.0702952344 5868605.033820355 20.442670747055647
(2) 660050.3347344951 5868606.121563466 20.574639679143946
(3) 660050.4376411334 5868606.55473629 19.53932546324279
(1) 660050.0702952344 5868605.033820355 20.442670747055647

FYI these are from CityGML which uses the COLLADA method for texture mapping.

Since the shape will always form a plane I can easily generate the equation of the plane, and equations of lines represented by each vertex pair. But I can't see how these will help me without knowing rotation of lines on the plane with respect to what is horizontal and vertical in texture space. So starting off by using Pythagoras on an edge isn't possible ... ?

I'm thinking that this must be a problem that has been solved ages ago by those coding object viewers which both texture map and show world space, but I can't find a solution so far ...

FYI this is related to an ongoing question by me here.

Thanks

1

1 Answers

1
votes

I'm probably understanding this wrong, but here goes.

You have a triangle with world space cartesian coords and texture coords, You want to find the worldspace distance of a unit in each texture dimension.

For convenience, triangle vertices A,B,C are structured:

{p:{x,y,z},s,t} 

To calculate the worldspace distance of a unit of T:

Sort the vertices in the S direction - lets put them in an array V[]

Example: If B.s < A.s < C.s then:

V[0] = B
V[1] = A 
V[2] = C 

Find the fraction along the edge opposite to V[1] where it intersects. (i.e. projected in the T direction)

fraction = (V[1].s-V[0].s)/(V[2].s-V[0].s)

Find coordinates of that point on the edge by linear interpolation between V[0] and V[2] . (interpolate all scalars in the object)

P = (V[0] * (1 - fraction)) + (V[2] * fraction)

Now you have end points of a vertically aligned span in T and can find its length:

dT = abs(V[1].t - P.t)

And you can calculate the worldspace distance of that span with pythagoras:

dW = distanceBetween(V[1].p, P.p)

Then the worldspace distance of a unit of T:

uT = dW/dT

You can do the same for S of course.

EDIT: More detail.... enter image description here

In the image above the idea is to work out the coordinates of P. Once you have that, you can work out the length of the line V[1]-P in the t direction, and in x,y,z which is enough to get your desired result.

If we know the scalar (0->1) parameter of P along the line V[0]V[2] (fraction) then we can find all components P(x,y,z,t) through linear interpolation. It turns out that parameter is the same as that of the S component of V[1] along the span in S of V[0]V[2], shown by the red horizontal lines.

Linear interpolation is like a weighted blend. Lets say that fraction is 0.33, then you can add:V[2]*0.33 + V[0]*(1 - 0.33) to find the point in between. It works for all components because the line V[0]V[2] is a straight line in cartesian space and in texture space. If you stored other values on those vertices, for example per vertex colors in RGBA, you could interpolate them the same way and know the color and alpha values at P.