How 3D library usually do it:
1) Split your quad into 2 triangles.
2) For each triangle vertex define texture coordinates (u, v) like (0, 0), (Width - 1, 0), (Width - 1, Height - 1). You can use universal float values, like 0..1, but it's not necessary, if you use one fixed texture resolution only.
3) Use
linear interpolation to get (u, v) values for all other points. It's usually done via following algorithm:
For each u and v you can obtain new value via u/v=a*x+b*y+c*z formula. But you need to find a, b and c coefficients first. It's actually very easy to do. As you have 3 vertices, you have
system of linear equations. Something like:
a*x1+b*y1+c*z1=u1
a*x2+b*y2+c*z2=u2
a*x3+b*y3+c*z3=u3
You should
solve it and find a, b and c. Via finding
inverse matrix for example.
4) Use u/v=a*x+b*y+c*z to find u/v values for all other points. Please note, that u/v value you'd get can be outside of initial 0..(Width - 1) or 0..(Height - 1) interval. It's up to you, how to solve this problem. You can fill such areas by some background color. Or just repeat texture via simple u=u mod Width formula.
For 2D case things are even easier:
a*x1+b*y1=u1
a*x2+b*y2=u2
That is much easier to solve.