I asked a question regarding Bi linear transformations and received this answer:
From that very page you posted, there's a link to the source code. I'll explain the bilinear transformation in
http://www.antigrain.com/__code/include/agg_trans_bilinear.h.html
The idea here is to find a transformation of the form:
output_x = a * input_x + b * input_x * input_y + c * input_y + d
output_y = e * input_x + f * input_x * input_y + g * input_y + h
The term "bilinear" comes from each of those equations being linear in either of the input coordinates by themselves. We want to solve for the right values of a, b, c, and d. Say you have the reference rectangle r1, r2, r3, r4 which you want to map to (0,0), (1,0), (0,1), (1,1) (or some image coordinate system).
For a,b,c,d:
0 = a * r1_x + b * r1_x * r1_y + c * r1_y + d
1 = a * r2_x + b * r2_x * r2_y + c * r2_y + d
0 = a * r3_x + b * r3_x * r3_y + c * r3_y + d
1 = a * r4_x + b * r4_x * r4_y + c * r4_y + d
For e,f,g,h:
0 = e * r1_x + f * r1_x * r1_y + g * r1_y + h
0 = e * r2_x + f * r2_x * r2_y + g * r2_y + h
1 = e * r3_x + f * r3_x * r3_y + g * r3_y + h
1 = e * r4_x + f * r4_x * r4_y + g * r4_y + h
You can solve this however you like best. (If you're familiar with matrix notation, these are two matrix equations for which the matrix is the same, and then you simply need to find the LU decomposition once, and solve the two unknown vectors). The coefficients are then applied to map the interior of the rectangle to the position in the rectangle.
The problem is, I have input_x and input_y aswell as r1, r2, r3, r4, but I'm not sure how to achieve output_x and output_y. How do I solve such an equation? I'm only familiar with solving equations with 2 variables.
Thanks