Function to map 2D coordinates from one quadrilateral to another

520 Views Asked by At

What would be a clean way to define a function $F : R^2 \rightarrow R^2$ that maps coordinates from one quadrilateral domain to another like the below image? (Assuming we know the coordinates of the 4 points of each quadrilateral)

Does it matter if one of them is non-convex or is it possible to get a single nice function that handles all cases? If non-convex cases complicate the mapping, what would be a nice function assuming that both are convex?

1

There are 1 best solutions below

1
On

This can be done using range-split operation, $A,B \in (\mathbb{R},\mathbb{R})$, $x \in [0..1]$:

  • RangeSplit($A$,$B$,$x$) = $(1.0-x) \cdot A+x\cdot B$.

If your original rectangle coordinates are $(x,y), x \in [0..w], y \in [0..h]$, and corners of new quad is $(A..B),(C..D)$, then the final solution would be:

  • $(x_0,y_0) = (x/w,y/h)$
  • $(x_r,y_r)$ = RangeSplit(RangeSplit($A$,$B$,$x_0$),RangeSplit($C$,$D$,$x_0$),$y_0$)