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:

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))
