Group Abstract Group Abstract

Message Boards Message Boards

0
|
11K Views
|
9 Replies
|
2 Total Likes
View groups...
Share
Share this post:

How to transform a Graphics?

Posted 6 years ago

I have to transform (namely translate and rotate) any 2D Graphics. Of course, I know about TranslationTransform, RotationTransform, GeometricTransformation, and the like. But they all act on graphics primitives, not on a completed Graphics.

I'm afraid it's a stupid question, but Is there some direct way to transform a Graphics? Something like:

g=Graphics[listOfPrimitives,options];
TranslationTransform[vShift]@*RotationTransform[theta, vOrigin] [g]

I could take the primitives and options of g by g[[1]] and Options[g] and write:

Graphics[GeometricTransformation[g[[1]], 
  TranslationTransform[vShift]@*RotationTransform[theta,vOrigin], 
 Options[g]]

but this looks pretty strange. And would it work with Images, Rasters within the primitives?

POSTED BY: Werner Geiger
9 Replies
Posted 6 years ago

Werner, maybe like this?

f[x_, theta_, vshift_] := Graphics[Translate[Rotate[First@x, theta, {0, 0}], vshift], Sequence @@ Rest@x]

g = Graphics[{EdgeForm[Black], Gray, Triangle[], Disk[{1, 1}, .25]}, 
  Axes -> True, AxesOrigin -> {0, 0}, PlotRange -> 2];

f[g, Pi/3, {0.6, 0.4}]

enter image description here

POSTED BY: Hans Milton
Posted 6 years ago

Hi Werner,

You can use Rotate to rotate.

g = Graphics[{Orange, RegularPolygon[3]}]
Rotate[g, Pi/2]

Edit For translation use Translate

POSTED BY: Rohit Namjoshi
Posted 6 years ago

Yes, it basically works in a way similar to your GeometricTransformation example. Also similar to Ian's MapAt. But what drawbacks do you see with these methods?

POSTED BY: Hans Milton
Posted 6 years ago

Isn't that exactly what GeometricTransformation does?

POSTED BY: Werner Geiger
Posted 6 years ago

Isn't that exactly what GeometricTransformation does?

POSTED BY: Werner Geiger

Another approach that might give you what you want is:

MapAt[Rotate[#, 30*Degree, {0, 0}] &, g, 1]

This gives:

enter image description here

Since the Head of the resulting expression is Graphics, the expression can be used in functions such as Show as in the following example:

Table[
  MapAt[Rotate[#, rot*Degree, {0, 0}] &, g, 1],
  {rot, 0, 360, 30}
  ] // Show

Which gives:

enter image description here

Hope this helps.

POSTED BY: Ian Williams
Posted 6 years ago

I also don't know but thank you to those who answer it. Now, I know.

POSTED BY: Yasmin Hussain
Posted 6 years ago

That's clear. But it transforms the primitives, just like GeometricTransformation, not the Graphics. And it requires knowledge of all primitives within the Graphics.

POSTED BY: Werner Geiger
POSTED BY: Diego Ramos
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard