5
$\begingroup$

I want to plot a rectangle using graphics :

rc = Graphics[{Blue, Rectangle[{0, 0}, {1, 1}]}];

and add a deformation function to it:

$$\chi(\mathbf X)=X_1(1+X_2)\hat{\mathbf e}_1+X_2(1+3X_1)\hat{\mathbf e}_2$$

This deformation function specifies new coordinates as functions of old ones. How can I plot the new shape?

$\endgroup$
10
  • $\begingroup$ Have you looked at this in the documentation? $\endgroup$
    – m_goldberg
    Jun 12, 2013 at 6:16
  • $\begingroup$ @m_goldberg, seeing as the deformation is of the three-dimensional sort, Graphics[] won't help the OP. Graphics3D[] might...maybe even ParametricPlot3D[]. $\endgroup$ Jun 12, 2013 at 6:17
  • $\begingroup$ @J. M. The reference I gave gives information on and further links to both 2D and 3D transforms. $\endgroup$
    – m_goldberg
    Jun 12, 2013 at 6:21
  • 2
    $\begingroup$ In that case, ponder upon the result of {ParametricPlot[{u, v}, {u, 0, 1}, {v, 0, 1}], ParametricPlot[{u (1 + v), v (1 + 3 u)}, {u, 0, 1}, {v, 0, 1}]} // GraphicsRow. $\endgroup$ Jun 12, 2013 at 6:31
  • 2
    $\begingroup$ If you understood how ParametricPlot[] worked in that snippet I posted, may I suggest writing an answer to your own question, so that we can gauge your understanding of that solution? $\endgroup$ Jun 12, 2013 at 6:56

2 Answers 2

9
$\begingroup$

As J. M. suggested in comments, ParametricPlot[] can be used to show this deformation:

{ParametricPlot[{u, v}, {u, 0, 1}, {v, 0, 1}], 
  ParametricPlot[{u (1 + v), v (1 + 3 u)}, {u, 0, 1}, {v, 0,1}]} // GraphicsRow 

enter image description here

$\endgroup$
1
  • $\begingroup$ Looks right, but the setting AspectRatio -> 1 will of course necessarily distort your region further. Someone looking at the pictures should then be careful to note that the scales on the axes in the picture on the left and the picture on the right are different. $\endgroup$ Jun 12, 2013 at 7:25
4
$\begingroup$

Another way of approaching this is to map the image of the rectangle rather than the geometric object itself.

img = Image[Graphics[{Blue, Rectangle[{0, 0}, {1, 1}]}]]

This turns the graphic into an image which can then be mapped using the specified function:

ImageForwardTransformation[img, {#[[1]] (1 + #[[2]])/4, #[[2]] (1 + 3 #[[1]])/4} &]

enter image description here

The only wrinkle here is that the range of the image needs to be in {0,1} so I scaled both entries by the largest value (4) so that would show the whole image of the distorted rectangle.

Of course, this method maps not only the rectangle itself, but also the contents of the rectangle (if any). So for example, the same mapping can be applied to an image.

img = Import["https://i.stack.imgur.com/6zVEI.png"];

enter image description here

ImageForwardTransformation[img, {#[[1]] (#[[2]] + 1)/4, 
                  (1 + 3 #[[1]]) #[[2]]/4} &, Background -> White]

enter image description here

$\endgroup$
1
  • $\begingroup$ Alternatively: ImageForwardTransformation[Image[Graphics[{Blue, Rectangle[{0, 0}, {1, 1}]}, ImagePadding -> None, PlotRangePadding -> None]], # ({#[[2]], 3 #[[1]]} + 1) &, Background -> 1., DataRange -> {{0, 1}, {0, 1}}, PlotRange -> {{0, 2}, {0, 4}}]. $\endgroup$ Jun 12, 2013 at 9:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.