TransWikia.com

ImageForwardTransformation always puts origin at lower left

Mathematica Asked by David E Speyer on December 17, 2020

I am trying to create a notebook which will graphically display the effect of simple geometric maps, for the purpose of teaching linear algebra. Here is what I thought would work.

I created an image called map. It is 920 pixels wide and 797 tall. Here it is displayed on background coordinate axes.

Show[map, Axes -> True, PlotRange -> {{-1200, 1200}, {-1200, 1200}}]

enter image description here

Now, I want to show this image rotated by $pi/6$ around $(0,0)$. Here is what I thought would work:

Show[
  ImageForwardTransformation[map, ({{Cos[Pi/6], -Sin[Pi/6]}, {Sin[Pi/6], Cos[Pi/6]}}.#) &,
    PlotRange -> All],
  Axes -> True, PlotRange -> {{-1200, 1200}, {-1200, 1200}}]

Here is the output:

enter image description here

As you can see, the origin is in the wrong place! I expected ImageForwardTransformation to create a new image whose image coordinates would be rotated from the old image coordinates. For example, if $0 < theta < pi/2$, and the old coordinates are $[0,w] times [0,h]$, then the new ones would be $[-(sin theta) h, (cos theta) w] times [0, (sin theta) w + (cos theta) h]$.
Instead, it seems that ‘ImageForwardTransform[]’ always translates the lower left pixel to be at $(0,0)$, so the new coordinates are $[0, (cos theta) w+(sin theta) h] times [0, (sin theta) w + (cos theta) h]$.

I tried a bunch of variants on the above code, but I think I am missing something basic and it probably isn’t useful to copy over all the failures. Is there an easy way to make ‘ImageForwardTransform[]’ work correctly with axes and other graphics objects? Or is there some variant function I should be using instead? (I tried ImageGraphics and Rotate instead, with the idea of using graphics objects everywhere instead of images, but that didn’t work either; I’ll add details of the failure if people want.)

One Answer

Maybe something like this:

Graphics[{
  GeometricTransformation[
   Inset[ExampleData@{"TestImage", "Mandrill"}, {0, 0}, {0, 0}, 70],
   RotationTransform[Pi/6]]
  }, Axes -> True, PlotRange -> 100]

Rotated Mandrill

Correct answer by Michael E2 on December 17, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP