I have a source image (arbitrary width and height c) shown here as a rectangle
[X1,X2,X3,X4]. It contains two points C and D (both known coordinates within the image - X4 / top left).
Then I have a target image (might have different height a and width b than source image) that contains two points A and B (|AB| doesn't necessarily equal |CD|). There's also a source of projection S.
I need to somehow calculate coordinates of a transformed rectangle (polygon) such that:
- Point C will always be mapped to A (therefore A will be equal to C) and D will be mapped to B (B = D)
- Point X3 of this newly calculated polygon will lie on a line between S and A/C (now identical)
- Point X4 will lie on a line from S to B/D.
- Distance from parallel lines
[X3,X4]will be still c. (If it turns out that it's not always possible to construct such a polygon the condition 4. can be dropped, and
[X1,X2]don't need to be parallel to
What I've tried
I thought I will solve it by:
- shrinking width of source image by ratio of |AB| and |CD|
- aligning C with A (move source image)
- finding angle difference 𝛼 between AB and CD
- rotating source image by angle 𝛼 (with center in C/A)
- calculating X3 and X4
But it doesn't work universally. Steps 1-4 work well, but then changing X3 and X4 moves C (resp. D) away from A (resp. B).