Group Abstract Group Abstract

Message Boards Message Boards

0
|
2.3K Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How can I rotate and paste a graphics object multiple times about a point?

Posted 5 years ago

This seems like a trivial operation, and it is in Adobe Illustrator and Inkscape, yet no matter what I try I can't get it to work and I have found absolutely nothing about how to do it in searching for days now.

FlasherSector =
 Graphics[{CV, Line[{{0, 0}, {PS/4, L1/2}}], CV,
   Line[{{0, 0}, {-PS/4, L1/2}}], CH, Line[{{0, 0}, {0, L1}}], CH,
   Line[{{-PS/4, L1/2}, {0, L1}}], CH, Line[{{0, L1}, {PS/2, L1}}],
   CV, Line[{{0, L1}, {-PS/4, L1}}], CH,
   Line[{{-PS/4, L1}, {-PS/2, L1}}], CV,
   Line[{{-PS/4, L1/2}, {-PS/4, 1.5 L1}}], CV,
   Line[{{PS/4, L1/2}, {0, L1}}], CV,
   Line[{{PS/2, L1}, {-PS/4, 1.5 L1}}], CH,
   Line[{{0, L1}, {-PS/4, 1.5 L1}}], CV,
   Line[{{-PS/4, 1.5 L1}, {-1.5 PS, 4 L1}}], CH,
   Line[{{PS/2, L1}, {-PS, 4 L1}}], CV,
   Line[{{PS/2, 2 L1}, {-PS/2, 4 L1}}], CH,
   Line[{{PS/2, 3 L1}, {0, 4 L1}}], CV,
   Line[{{PS/2, L1}, {PS/2, 2 L1}}], CH,
   Line[{{PS/2, 2 L1}, {PS/2, 3 L1}}], CV,
   Line[{{PS/2, 3 L1}, {PS/2, 4 L1}}], CH,
   Line[{{PS/2, L1}, {2 PS, 4 L1}}], CV,
   Line[{{PS/2, 2 L1}, {1.5 PS, 4 L1}}], CH,
   Line[{{PS/2, 3 L1}, {PS, 4 L1}}], CS,
   Line[{{-2 PS, 4 L1}, {2 PS, 4 L1}}]}]

   Rotate[FlasherSector, IA, {0, 0}]

RotFlasher[t_] := Rotate[FlasherSector, t, {0, 0}]
i = 1
RotFlasher[i*IA]

Do[RotFlasher[i*IA], {i, PN}]

The images should explain what I am trying to do. Bottom line,

Do[RotFlasher[i*IA], {i, PN}] 

is not working. What would?

Mathematica

This is what I expect and what I got in Illustrator:

Illustrator

POSTED BY: Paco Hidalgo
4 Replies
Posted 5 years ago

I just saw this now. Thank you Rohit for your explanation. Since last time, I actually changed my code to make FlasherSector a list of lines and then did a Table rotation of the list and created a Graphics object with the table. This was what I wanted because now I can export an accurate PDF with exact sizes and location of objects and absolute linewidths. Thanks for your help. enter image description here enter image description here

POSTED BY: Paco Hidalgo
Posted 5 years ago

Thank you Rohit! This idea worked! I tried Table first but got an array as shown. What I was missing was the Graphics line. Looking up each part of it, I still don't fully understand how it works. Could you please explain in detail how it works? I want to understand it thoroughly for future reference. Thanks again.

t = Table[Rotate[FlasherSector, i*IA, {0, 0}], {i, PN}] t /. Graphics -> Identity // Graphics

table

POSTED BY: Paco Hidalgo
Posted 5 years ago

Hi Paco,

The usual way to combine multiple Graphics is to use Show.

g1 = Graphics[{Red, Disk[]}];
g2 = Graphics[{Blue, RegularPolygon[3]}];
Show[g1, g2]

That does not work if the Graphics is rotated

g2r = Rotate[g2, Pi/2];
Show[g1, g2r]
(* Show: Could not combine the graphics objects in Show *)

The reason is that the Head of g2r is Rotate, not Graphics.

g2r // InputForm
(* Rotate[Graphics[{RGBColor[0, 0, 1], RegularPolygon[3]}], Pi/2] *)

We need to swap the Rotate and the Graphics. The Rule replaces Graphics with the identity function Identity and then passes it to Graphics.

g2r /. Graphics -> Identity // Graphics // InputForm
(* Graphics[Rotate[{RGBColor[0, 0, 1], RegularPolygon[3]}, Pi/2]] *)

The best way is to avoid this is to perform the Rotate before passing it to Graphics

gr2 = Graphics[Rotate[{Blue, RegularPolygon[3]}, Pi/2, {0, 0}]];
Show[g1, gr2]

I suggested the former because it required minimal changes to your code. To try the better approach, use Table to generate a list of the rotations of the primitives {CV, Line[{{0, 0}, {PS/4, L1/2}}], ...} and then pass it to Graphics.

POSTED BY: Rohit Namjoshi
Posted 5 years ago

Hi dpt1221tpd,

Please provide the values for CV, PS,L1`, ... so we can reproduce your results.

WL is very different from Illustrator and Inkscape. The Do loop calls RotFlasher PN times but does nothing with the result. Here is one way to do it

SeedRandom[111];
g := Graphics[{RandomColor[], RegularPolygon[{1.5, 0}, {1, Pi/3}, 3]}]

t = Table[Rotate[g, n , {0, 0}], {n, Pi/3, 2 Pi, Pi/3}];

t /. Graphics -> Identity // Graphics

enter image description here

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