Message Boards Message Boards

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

How to transform a Graphics?

Posted 4 years ago
POSTED BY: Werner Geiger
9 Replies

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 4 years ago

Isn't that exactly what GeometricTransformation does?

POSTED BY: Werner Geiger
Posted 4 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 4 years ago

Isn't that exactly what GeometricTransformation does?

POSTED BY: Werner Geiger
Posted 4 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 4 years ago

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

POSTED BY: Yasmin Hussain
Posted 4 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

Operate over the complete Graphics command may produce undesired outputs, as the coordinates axes are not left fixed. One way is to use Rule transformations on the Graphics Primitives that you need as follows

POSTED BY: Diego Ramos
Posted 4 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
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract