Mapping a rectangle to a scaled and rotated rectangle

140 Views Asked by At

How to find a mapping $f:\mathbb{R}^2\to \mathbb{R}^2$ which maps the rectangular region with corners $(x_1,y_1),(x_1,y_2),(x_2,y_1),(x_2,y_2)$ to another rectangular region where $f(x_1,y_1)=(x_1,\frac{y_1+y_2}{2}),f(x_1,y_2)=(\frac{x_1+x_2}{2},y_2),f(x_2,y_2)=(x_2,\frac{y_1+y_2}{2}),$ $f(x_2,y_1)=(\frac{x_1+x_2}{2},y_1)$ ?

Edit:

An illustration of the mapping I am trying to get. The function $f$ should map the gray region in the first image to the gray region in the second. By mapping, I mean a continuous function( guess this will be a contraction)

3

There are 3 best solutions below

0
On BEST ANSWER

Here's a simpler approach. As this transformation can be done with a line-preserving mapping, then it has to be a linear mapping. You may therefore write: $$ f(x,y)=(ax+by+c,\ dx+ey+f), $$ where $a$, $b$, $c$, $d$, $e$, $f$ are six constant coefficients to be determined. To find them, you can use the first three given constraints: $$ f(x_1,y_1)=\Big(x_1,\frac{y_1+y_2}{2}\Big), \quad f(x_1,y_2)=\Big(\frac{x_1+x_2}{2},y_2\Big), \quad f(x_2,y_2)=\Big(x_2,\frac{y_1+y_2}{2}\Big). $$ These amount to six linear equations, which can be easily solved to get: $$ a= \frac{1}{2},\ b= \frac{ x_1- x_2}{2( y_1- y_2)},\ c= \frac{x_2 y_1 -x_1 y_2}{2 ( y_1- y_2)},\ d= \frac{ y_2- y_1}{2( x_1- x_2)},\ e= \frac{1}{2},\ f= \frac{x_1 y_1 -x_2 y_2}{2 ( x_1- x_2)}. $$ You can check that the fourth constraint is also satisfied.

0
On

Well, once you draw a picture it's pretty clear that this can be done by an affine map (i.e., linear-with-translation). But before I get to that, I want to point out that you can define it really stupidly, by saying \begin{align} f(x_1,y_1)&=(x_1,\frac{y_1+y_2}{2})\\ f(x_1,y_2)&=(\frac{x_1+x_2}{2},y_2)\\ f(x_2,y_2)&=(x_2,\frac{y_1+y_2}{2})\\ f(x_2,y_1)&=(\frac{x_1+x_2}{2},y_1)\\ f(x, y) &= (x, y) &\text{otherwise} \end{align} because your question didn't actually require continuity or bijectivity or any of those other "obvious" things.

To solve the problem you probably meant to ask, notice that if the map is affine, then it sends lines to lines, and preserves intersections, hence the point $$ P = (\frac{x_1 + x_2}{2}, \frac{y_1+y_2}{2}) $$ remains fixed. Define $$ T(a, b) = (a, b) - P = (a - \frac{x_1+x_2}{2}, b - \frac{y_1+y_2}{2}) $$ In fact, to clean things up a little, I'm going to let $$ p = \frac{x_1 + x_2}{2}\\ q = \frac{y_1 + y_2}{2} $$ so that the point $M = (p,q)$, is the center of your original rectangle. Now the function $T$ is just $$ T(x, y) = (x-p, y-q) $$

Calling your four points, $A,B,C,D$, we have that $T(A), T(B), T(C), T(D)$ form a rectangle centered at the origin. The height of the rectangle is $y_2 - y_1$; the width is $x_2 - x_1$, i.e., the width and height of the original rectangle.

We need to transform it so that $A$ goes to $(A+B)/2$, etc. Now let $$ S(a, b) = (\frac{a}{\frac{x_2-x_1}{2}}, \frac{b}{\frac{y_2-y_1}{2}}). $$ Then we have $S(T(A)) = (-1, -1), S(T(B)) = (-1, 1), S(T(C)) = (1,1)$, and $S(T(D)) = (1, -1)$. We want to send these four points to $(-1, 0)$, $(0, 1)$, $(1, 0)$ and $(0, -1)$, respectively. Concentrating on the second and third, I'm going to observe that left-multiplication by the matrix $$ M = \pmatrix{1 & -1 \\ 1 & 1} $$ (when we write our points as column-vectors!) does exactly the opposite: it sends $(1,0)$ to $(1,1)$ and $(0, 1)$ to $(-1, 1)$. That means that its inverse, $$ N = \frac{1}{2}\pmatrix{1 & 1 \\ -1 & 1} $$ sends $(1,1)$ to $(1,0)$ and $(-1, 1)$ to $(0, 1)$. You can check that it sends the other two to the right places as well. Writing out $$ N \pmatrix{x\\y} = \pmatrix{\frac{x+y}{2}\\ \frac{-x+y}{2}} $$ we get a third function, $$ U(x, y) = (\frac{x+y}{2}, \frac{-x+y}{2}) $$ So the function $$ (x, y) \mapsto T^{-1}(S^{-1}(U(S(T(x,y))))) $$ is the map you want. Letting $h = (y_2 - y_1)$ and $w = (x_2 - x_1)$ denote the height and width, we have $$ T(x, y) = (x-p, x-q)\\ T^{-1}(x, y) = (x+p, x+q)\\ S(x, y) = (\frac{2x}{w}, \frac{2y}{h})\\ S^{-1}(x, y) = (\frac{wx}{2}, \frac{hy}{2})\\ U(x, y) = (\frac{x+y}{2}, \frac{-x+y}{2}) $$ so that the composite is \begin{align} T^{-1}(S^{-1}(U(S(T(x,y))))) &= T^{-1}(S^{-1}(U(S(x-p, y-q))))\\ &=T^{-1}(S^{-1}(U(\frac{2(x-p)}{w}, \frac{2(y-q)}{h})))\\ &=T^{-1}(S^{-1}\left( \frac{\frac{2(x-p)}{w} + \frac{2(y-q)}{h} }{2}, \frac{ -\frac{2(x-p)}{w}+ \frac{2(y-q)}{h}}{2} \right))\\ &=T^{-1}(S^{-1}\left( \frac{(x-p)}{w} + \frac{(y-q)}{h}, -\frac{(x-p)}{w}+ \frac{(y-q)}{h}\right))\\ &=T^{-1}\left(\frac{w}{2} \left( \frac{(x-p)}{w} + \frac{(y-q)}{h}\right), \frac{h}{2} \left( -\frac{(x-p)}{w}+ \frac{(y-q)}{h}\right) \right))\\ &=\left(p + \frac{w}{2} \left( \frac{(x-p)}{w} + \frac{(y-q)}{h}\right),q + \frac{h}{2} \left( -\frac{(x-p)}{w}+ \frac{(y-q)}{h}\right) \right) \end{align}

Now all you have to do is substitute in the values of $p, q, h, w$ given above, simplify like mad, and you'll have a nice clean answer that gives no insight at all into why it's correct. Or you can leave it in the form just after "so that the composite is", which tells the whole story. It's up to you.

so that

0
On

Writing $\mathbf p_{ij}=(x_i,y_j)^T$ and using homogeneous coordinates, the matrix of this affine map is given by \begin{align} M &=\begin{bmatrix} f(\mathbf p_{11}) & f(\mathbf p_{12}) & f(\mathbf p_{21}) \\ 1&1&1\end{bmatrix} \begin{bmatrix}\mathbf p_{11} & \mathbf p_{12} & \mathbf p_{21} \\ 1&1&1 \end{bmatrix}^{-1} \\ &= \begin{bmatrix} x_1 & \frac12(x_1+x_2) & \frac12(x_1+x_2)\\ \frac12(y_1+y_2) & y_2 & y_1 \\ 1&1&1 \end{bmatrix} \begin{bmatrix}x_1&x_1&x_2\\y_1&y_2&y_1\\1&1&1\end{bmatrix}^{-1} \\ &= \begin{bmatrix} \frac12 & {x_1-x_2\over2(y_1-y_2)} & {x_2y_1-x_1y_2\over2(y_1-y_2)} \\ {y_2-y_1\over2(x_1-x_2)} & \frac12 & {x_1y_1-x_2y_2\over2(x_1-x_2)} \\ 0&0&1 \end{bmatrix}. \end{align} We could’ve used any 3 out of the four point pairs to construct $M$. As a check, we compute $$M\begin{bmatrix}x_2\\y_2\\1\end{bmatrix} = \begin{bmatrix}x_2\\\frac12(y_1+y_2)\\1\end{bmatrix},$$ as required.