0
$\begingroup$

Can we construct parallel movement function which act on Graphics primitive or Graphics?

Example of Graphics primitive : Circle[{0,0},1]

Example of Graphics : Graphics[Circle[{0,0},1]]

For example, can you construct function F or G ? (I want both)

enter image description here

The unit of parallel movement must be user unit.
I mean the radius length of Circle[{0,0},1] is 1 user unit.

Hope the function (F or G) do not rely on Inset.
It's too difficult to handle Inset accurately with my skills, so I want to avoid Inset as much as possible (for a while).

Also I hope the function should act correctly on complicated case, like nested structure of Graphics/Show/Inset.

If there is no direct method, then we should be able to do followings :

  1. extract every graphic primitives from nested structure of Graphics/Show/Inset
  2. apply parallel movement for all those graphic primitives
  3. combine processed graphic primitives

The code would be lengthy and difficult to make but it would be useful. Anyone who doesn't have that code or have no time but think there is no direct method, please leave it as comment. Thank you!

$\endgroup$
4
  • 2
    $\begingroup$ Have you explored TranslationTransform? $\endgroup$
    – Syed
    Jun 7 at 12:58
  • $\begingroup$ No, it is new to me. $\endgroup$
    – imida k
    Jun 7 at 13:03
  • $\begingroup$ Thank you! I think the problem was solved for graphics primitive. CanTranslationTransform be applied easily for graphics of complicated structures? $\endgroup$
    – imida k
    Jun 7 at 13:18
  • 1
    $\begingroup$ Perhaps GraphicsComplex could handle the nested structure you have but I am not conversant with its use. $\endgroup$
    – Syed
    Jun 7 at 13:23

3 Answers 3

1
$\begingroup$
F[t_] := Translate[#, t] &;
G[t_] := MapAt[F[t], {1}];


Graphics[{Circle[], Line[{{.5, 0}, {.5, 1}}], 
  F[{1, 0}]@{Circle[], Red, Line[{{.5, 0}, {.5, 1}}]}}]

enter image description here

Show[Graphics[{Circle[], Line[{{.5, 0}, {.5, 1}}]}], 
 G[{1, 0}] @ Graphics[{Circle[{1, 0}, 1], Red, Line[{{.5, 0}, {.5, 1}}]}]]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thank you, so far everything works perfectly with this. For example it works OK with Imagesize->1->50. This is the orthodox method for combining graphics. $\endgroup$
    – imida k
    Jun 12 at 22:46
2
$\begingroup$

Try

circle = Circle[{0, 0}, 1]
Graphics[{circle, TranslationTransform[{1, 0}][circle]}]
$\endgroup$
6
  • $\begingroup$ Thank you, you've succeeded to make such F. Can you also make such G ? $\endgroup$
    – imida k
    Jun 9 at 9:14
  • $\begingroup$ What is the difference between F and G? $\endgroup$ Jun 9 at 11:50
  • $\begingroup$ Imagine a very complicated nested structure of Graphics/Show/Inset/... Anyway it is Graphics (the head is Graphics). Name it G. Can you do translation transformation by {1,0}, to G easily? $\endgroup$
    – imida k
    Jun 9 at 11:57
  • $\begingroup$ No I don't think it is possible because TranslationTransform and similar transformations are applied to graphics-primitives only. $\endgroup$ Jun 9 at 12:04
  • $\begingroup$ But probably you may agree this can be done in other way. There may be built-in commands that act on the entire Graphics, or.. It may a bit difficult, but first analyzing the given graphic, then translating each graphic primitives. $\endgroup$
    – imida k
    Jun 9 at 12:08
0
$\begingroup$

My answer is not complete, for example it does not work well with Graphics containing Inset. To be specific, the text used in Inset does not move along other Graphics primitives.

Anyway my trial is

trs[G_, {x_, y_}] := 
 Graphics@GeometricTransformation[#, {x, y}] &@
    GraphicsGroup@Delete[#, 0] &@G

where G is a Graphics and {x,y} is a coordinate of translation.

enter image description here

Hope other users improve this code, and post it. Other codes are

{Graphics[Circle[]],
 trs[Graphics[{Red, Disk[], Green, Rectangle[{0, 0}, {2, 2}], Blue, 
    Disk[{2, 2}]}], {2, -2}],
 trs[Graphics[Polygon[{{0, 0}, {1, 1}, {0, 1}, {1, 0}}]], {0, -4}],
 trs[Graphics[{Pink, Disk[], {Blue, Disk[{1, 0}]}, 
    Disk[{2, 0}]}], {0, -6}]}

Show[Graphics[Circle[]],
 trs[Graphics[{Red, Disk[], Green, Rectangle[{0, 0}, {2, 2}], Blue, 
    Disk[{2, 2}]}], {2, -2}],
 trs[Graphics[Polygon[{{0, 0}, {1, 1}, {0, 1}, {1, 0}}]], {0, -4}],
 trs[Graphics[{Pink, Disk[], {Blue, Disk[{1, 0}]}, 
    Disk[{2, 0}]}], {0, -6}]]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.