Undistorted texture coordinates

How do you calculate the UV coordinates for points on a plane?

I have a polygon - 3 or 4 or more points, that is, on a plane, i.e. all points are on the plane. But it can be at any angle in space.

One side of this polygon - two points - must be mapped to two corresponding points in the texture - I know these two points in advance. I also know the x and y scale for the texture and that no dots extend beyond the texture or other “edge cases”.

Here's the image in which the most textured square is distorted:

enter image description here

I have indicated a bad square in yellow. Imagine that I know the UV coordinates of these two lower corners on this quadrant and want to calculate the correct UV coordinates of the other two points ...

- ?

, - , () . , . , ?

? 2D-?


brainjam:

def set_texture(self,texture,a_ofs,a,b):
    self.texture = texture
    self.colour = (1,1,1)
    self.texture_coords = tx = []
    A, B = self.m[a_ofs:a_ofs+2]
    for P in self.m:
        if P == A:
            tx.append(a)
        elif P == B:
            tx.append(b)
        else:
            scale = P.distance(A)/B.distance(A)
            theta = (P-A).dot((B-A)/(P.distance(A)*B.distance(A)))
            theta = math.acos(theta)
            x, y = b[0]-a[0], b[1]-a[1]
            x, y = x*math.cos(theta) - y*math.sin(theta), \
                x*math.sin(theta) + y*math.cos(theta)
            x, y = a[0]+ x*scale, a[1]+ y*scale
            tx.append((x,y))

enter image description here

+3
3

, , UV- . A, B, C, D. - a, b, c, d, a b.

, , P , - p. ( , UV- c d C D, P .)

& theta; P-A B-A. dot product acos.

& ; = (P-A) & sdot; ( B-A)/(| P-A || B-A |)

& ; = acos (& alpha;)

:

& Sigma; = | P-A |/| B-A |

, p -, b-a & theta; ( a) & sigma;.

R, & theta;, be

| + cos (& theta;) -sin (& theta;) |
| + sin (& theta;) + cos (& theta;) |

p= a + & sigma; R (b-a).

.

+1

.

- :

3 3D UV-:

  • (, , , , )
  • (, , , , )
  • (, , , , )

, x, y, z, D :

D = A + (B - A) + beta (C - A) + (B - A) X (C - A)

3 x, y, z, X - , , , . , uv xyz.

W = (B - A) X (C - A), :

Dx - Ax = alpha. (Bx-Ax) + beta. (Cx-Ax) + gamma.Wx

Dy - Ay = (By-Ay) + beta. (Cy-Ay) + gamma.Wy

Dz - Az = (Bz-Az) + beta. (Cz-Az) + gamma.Wz

M :

       | (Bx-Ax) , Cx-Ax , Wx | 
   M = | (By-Ay) , Cy-Ay , Wy | 
       | (Bz-Az) , Cz-Az , Wz | 

N, , D.

, , D :

(, , ) = N. (D-A)

u, v D :

Du = Au + alpha (Bu - Au) + beta (Cu - Au)

Dv = Av + ​​alpha (Bv - Av) + beta (Cv - Av)

, D 3D (A, B, C) 3D-.

+2

U and V are numbers from 0 to 1.

So, let's say, in your situation, the size of the larger edge is 10, and the smaller is 5, each “gap” is 2.5. Then it normalizes to give you the number you need.

so some pseudo-code example:

bottomLeftVector(0,0,0)
bottomLeftTexture(0,0)
topLeftVector(2.5, 5, 0)
topLeftTexture(0.25, 0)
topRightVector(7.5, 5, 0)
topRightTexture(0, 0.75)
bottomRightVector(10, 0, 0)
bottomRightTexture(1,1)

Hope this helps!

0
source

All Articles