Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Background: I am working on a program that produces design patterns ( using wallpaper- and frieze-group theory ). This is for example a 'generating region' for a frieze or a wallpaper.

   Graphics[Polygon[{{.1, .1}, {.3, .8}, {1, .1}, {.5, .5}}]]

In reality this piece of Mathematica Graphics code is the result of many ( matrix- ) calculations.

Usually I want this in a larger size, for example 1 by 2:

   Graphics[{Polygon[{{.1, .1}, {.3, .8}, {1, .1}, {.5, .5}}], 
    Polygon[{{1.1, .1}, {1.3, .8}, {2, .1}, {1.5, .5}}]}]

Currently I work as follows: ===pseudocode=== follows:

  Map[ CalculateBaseMotif[#1,#2] &, 
       Flatten[Map[# &, Table[{ii, jj}, {ii, 1, lenX}, {jj, 1, lenY}]], 1]

So CalculateBaseMotif is calculated over and over. While all I want is to transtlate the result of

   G=Graphics[Polygon[{{.1, .1}, {.3, .8}, {1, .1}, {.5, .5}}]].

Summarizing: I make a ( complicated ) graphic G requiring many calculations of width W and height H. Then I want to produce a ( final ) graphic like so:

  GGGG
  GGGG

thus having width 4 x W and height 2 x H in the most efficient manner.

Question: How to define and work with temporary graphics data ?

share|improve this question
add comment

2 Answers

up vote 10 down vote accepted

You can use Translate for this, e.g.

With[{w = 5, h = 4, gr = Polygon[RandomReal[1, {20, 2}]]},
 Graphics[Translate[gr, Tuples[{Range[w], Range[h]}] - 1]]]

Mathematica graphics

share|improve this answer
    
This will speed up things nicely. –  ndroock1 May 18 '12 at 12:11
    
I like the Tuples iterator. Would have gone for a Table out of old ingrained procedural habit. –  Yves Klett May 18 '12 at 12:16
    
There's a problem with geometric transformations in graphics: ToBoxes processes them using some recusrive function, so if we try to make more than ~$IterationLimit/2 copies (4096 by default) of an object using e.g. GeometricTransformation, then it will fail. I hit this problem a few days ago, in 3D: Graphics3D@ GeometricTransformation[Sphere[], TranslationTransform /@ N@Tuples[Range[14], {3}]]. Strangely Translate doesn't have the problem... –  Szabolcs May 18 '12 at 12:18
    
Since Range is Listable you could write: Tuples @ Range @ {w, h} (+1) –  Mr.Wizard May 18 '12 at 12:26
    
@Szabolcs Do you think this $iterationLimit/2 limit should be reported as a bug? –  Jens May 18 '12 at 14:14
show 1 more comment

Just for completeness, I checked whether there is a failure due to $IterationLimit if one re-casts the tiling using GeometricTransformation. Although there is indeed a problem in 3D graphics if you tile more than 4096 (by default) 3d objects, as mentioned by @Szabolcs in the comment to Heike's answer, that fortunately doesn't seem to happen for the 2D graphics in this question.

Here is a test where I decided to use the at function from this answer, defined as follows

at[position_, angle_: 0][obj_] := 
 GeometricTransformation[obj, 
  Composition[
   TranslationTransform[position], 
   RotationTransform[angle]
 ]
]

With[
 {
  w = 8, h = 8,
  gr = {Orange, Disk[{0, 0}, {.1, .2}]}
 },
 Graphics[
  Map[(gr // at[#, ArcTan[Sin[#[[1]]]/Cos[#[[2]]]]]) &,
   Tuples[{Range[w], Range[h]}] - 1]]]

tiling

If you increase w and h to 70 both, it takes much longer but still works.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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