Skip to main content
Remove 'PointQ', which results in an error in 11
Source Link
orome
  • 12.9k
  • 3
  • 55
  • 101
pointQ[p_] := VectorQ[p, NumberQ] && Length[p] == 2
image[T_, object_] := object /. pt_?pointQ :> T[pt] 

reflect[p_?PointQ]reflect[p_] := {-p[[1]], p[[2]]}
pointQ[p_] := VectorQ[p, NumberQ] && Length[p] == 2
image[T_, object_] := object /. pt_?pointQ :> T[pt] 

reflect[p_?PointQ] := {-p[[1]], p[[2]]}
pointQ[p_] := VectorQ[p, NumberQ] && Length[p] == 2
image[T_, object_] := object /. pt_?pointQ :> T[pt] 

reflect[p_] := {-p[[1]], p[[2]]}
Added section on animating the graphic
Source Link
murray
  • 12.1k
  • 2
  • 26
  • 50

If you want to animate the transformation, showing over time how the cat's face changes from its original shape to the distorted shape, create a table of snapshots and export it, like this:

With[{mat = {{0.8, 0.35}, {-0.75, 1.5}}}, 
   twistingCat = 
      Table[Row[{makeFigure[newUrCat, -2, 2], Spacer[10], 
                 makeFigure[
                    GeometricTransformation[
                       newUrCat, (1 - t) IdentityMatrix[2] + t mat], -2, 2]}],
          {t, 0, 1, 0.05}]
];

ListAnimate[twistingCat]

In order to show the effect in this post, I created the list of "frames" for the animation above (which you would directly see inside Mathematica by evaluating the ListAnimate expression; by exporting that as a .gif, then placing that .gif here, you see the animation.

Export["TwistingCat.gif", twistingCat]

enter image description here

With similar techniques you may use one or more parameters in the transformation matrix and dynamically show the effect of varying them.

Note that ordinarily to display a dynamically changing graphic in a Mathematica notebook, I would use `Manipulate, as in:

With[{mat = {{0.8, 0.35}, {-0.75, 1.5}}}, 
   Manipulate[
      Row[{makeFigure[newUrCat, -2, 2], Spacer[10], 
           makeFigure[
              GeometricTransformation[newUrCat, (1 - t) IdentityMatrix[2] + t mat], -2, 2]}],
   {t, 0, 1, 0.05}]
]

If you want to animate the transformation, showing over time how the cat's face changes from its original shape to the distorted shape, create a table of snapshots and export it, like this:

With[{mat = {{0.8, 0.35}, {-0.75, 1.5}}}, 
   twistingCat = 
      Table[Row[{makeFigure[newUrCat, -2, 2], Spacer[10], 
                 makeFigure[
                    GeometricTransformation[
                       newUrCat, (1 - t) IdentityMatrix[2] + t mat], -2, 2]}],
          {t, 0, 1, 0.05}]
];

ListAnimate[twistingCat]

In order to show the effect in this post, I created the list of "frames" for the animation above (which you would directly see inside Mathematica by evaluating the ListAnimate expression; by exporting that as a .gif, then placing that .gif here, you see the animation.

Export["TwistingCat.gif", twistingCat]

enter image description here

With similar techniques you may use one or more parameters in the transformation matrix and dynamically show the effect of varying them.

Note that ordinarily to display a dynamically changing graphic in a Mathematica notebook, I would use `Manipulate, as in:

With[{mat = {{0.8, 0.35}, {-0.75, 1.5}}}, 
   Manipulate[
      Row[{makeFigure[newUrCat, -2, 2], Spacer[10], 
           makeFigure[
              GeometricTransformation[newUrCat, (1 - t) IdentityMatrix[2] + t mat], -2, 2]}],
   {t, 0, 1, 0.05}]
]
Added: use of GeometricTransformation.
Source Link
murray
  • 12.1k
  • 2
  • 26
  • 50

The code above "gets back to basics" in that the transformation operates directly upon points and in effect transforms a line segment of a graphical object by forming the corresponding line segment joining the images of the endpoints. Of course it

The can be simplified by using the built-in function GeometricTransformation. In particular, the outline of the cat's face can then be prescribed as an ellipse, and the second argument to GeometricTransformation allows direct use of the matrix, without any need to define the linear transformation T. Thus:

newOutline = Circle[{0, 0}, {0.88, 0.75}];
newUrCat = Join[{outline, mouth}, ears, eyes, whiskers];
newMakeFigureAndImage[objects_, mat_, low_ : -1, high_ : 1] :=
  Row[{makeFigure[objects, low, high], Spacer[10], 
       makeFigure[GeometricTransformation[objects, mat], low, high]}]
newMakeFigureAndImage[newUrCat, {{0.8, 0.35}, {-0.75, 1.5}}, -2, 2]

The output will appear identical to that above.

The code above "gets back to basics". Of course it can be simplified by using the built-in function GeometricTransformation. In particular, the second argument to GeometricTransformation allows direct use of the matrix, without any need to define the linear transformation T.

The code above "gets back to basics" in that the transformation operates directly upon points and in effect transforms a line segment of a graphical object by forming the corresponding line segment joining the images of the endpoints.

The can be simplified by using the built-in function GeometricTransformation. In particular, the outline of the cat's face can then be prescribed as an ellipse, and the second argument to GeometricTransformation allows direct use of the matrix, without any need to define the linear transformation T. Thus:

newOutline = Circle[{0, 0}, {0.88, 0.75}];
newUrCat = Join[{outline, mouth}, ears, eyes, whiskers];
newMakeFigureAndImage[objects_, mat_, low_ : -1, high_ : 1] :=
  Row[{makeFigure[objects, low, high], Spacer[10], 
       makeFigure[GeometricTransformation[objects, mat], low, high]}]
newMakeFigureAndImage[newUrCat, {{0.8, 0.35}, {-0.75, 1.5}}, -2, 2]

The output will appear identical to that above.

Added: use of GeometricTransformation.
Source Link
murray
  • 12.1k
  • 2
  • 26
  • 50
Loading
added 79 characters in body
Source Link
murray
  • 12.1k
  • 2
  • 26
  • 50
Loading
Source Link
murray
  • 12.1k
  • 2
  • 26
  • 50
Loading