16
$\begingroup$

Bug introduced in 8.0.4 or earlier and persisting through 11.2.0 or later


(Edited to simplify drawing)

I have a drawing of two tangent circles:

circles = {Circle[{0, 0}, 1], Circle[{0, 0.5}, 0.5]};
Graphics[circles, ImageSize -> Small]

enter image description here

But when I draw a transformed version of it, the circles become misaligned in an erratic fashion. It seems to be dependent on the PlotRange or something like that:

GraphicsGrid@
 Partition[
  Table[Graphics[
    Rotate[Scale[circles, 12, {0, 0}], -45 Degree, {0, 0}], 
    PlotRange -> {{-a, a}, {-a, a}}, ImageSize -> 100], {a, 11, 20}], 
  5]

enter image description here

The error does not occur if either Scale or Rotate are removed, so apparently the two transformations are interacting badly. But why should they? Am I doing something wrong, or is this a bug?

(N.B. This is with a fresh kernel; Mathematica 10.0.1 on Mac.)


Right now I'm getting around the problem by defining something like

scaledCircles = With[{s = 12}, 
   circles /. Circle[{x_, y_}, r_] :> Circle[{s x, s y}, s r]];

and then only applying Rotate to it. But that's no way to live.

The documentation states that "When possible, Normal will transform the coordinates explicitly" and gives an example of the form Normal@Scale[Cuboid...]. So if it worked it would be a nice and automatic way to do my workaround. But Normal doesn't work on scaled circles, for no reason I can fathom.

$\endgroup$
  • $\begingroup$ I observe the same erratic behavior in versions 8.0.4 and 10.0.1 under Windows 7. It depends on the Magnification of the Notebook. Very weird. $\endgroup$ – Alexey Popkov Nov 19 '14 at 15:33
  • 1
    $\begingroup$ There's some snapping involved that happens at a different rate for the ellipse and for the flat disks. This makes it evident: Manipulate[Graphics[Rotate[Scale[eye, 12.], -π/4], PlotRange -> {{-a, a}, {-a, a}}], {a, 100, 140}] $\endgroup$ – gpap Nov 19 '14 at 16:50
  • $\begingroup$ Same on Mac OSX 10.9.5, MMA V10 & V9 $\endgroup$ – SquareOne Nov 20 '14 at 1:04
  • 1
    $\begingroup$ I think you should report it to WRI. I cannot believe that it can be called the expected behavior. Clearly it is a bug. $\endgroup$ – Alexey Popkov Nov 20 '14 at 11:35
  • $\begingroup$ Related: mathematica.stackexchange.com/questions/9560/… $\endgroup$ – Michael E2 Aug 17 '15 at 16:13
7
$\begingroup$

I reported the issue to WRI on November 21. On December 16 they confirmed that it is a known bug. (I forgot to update the question till now.)

$\endgroup$
3
$\begingroup$

Just as a complementary and extended comment and as was recently observed in a related post, you get exactly the same problem if, not surprisingly, you use geometric transformation functions instead:

Given the initial object to transform:

circles = {Circle[{0, 0}, 1], Circle[{0, 0.5}, 0.5]};

the OP transformation:

t1 = Rotate[Scale[circles, 12], -45 Degree, {0, 0}];

is equivalent to:

t2 = GeometricTransformation[circles, 
   ScalingTransform[{12, 12}].RotationTransform[-45 Degree, {0, 0}]];

and you can check they exactly superimpose:

GraphicsGrid@Partition[Table[Graphics[{t1,t2},
    PlotRange -> {{-a, a}, {-a, a}}, ImageSize -> 100], {a, 11, 20}], 5]

enter image description here

You can also observe this strange behaviour just by manually resizing the graphic:

Graphics[t2] (* or Graphics[t1] *) 

enter image description here

enter image description here

enter image description here

$\endgroup$
2
$\begingroup$

Probably the best way to get around this issue is to make sure that the transformation is calculated explicitly before Graphics has to draw it. You can use TransformedRegion for this:

rotatedCircles = TransformedRegion[
  #, 
  ScalingTransform[{12, 12}, {0, 0}] @* RotationTransform[-45 Degree]
]& /@ circles

Graphics[rotatedCircles]

Note that rotatedCircles has evaluated and no longer has a transformation wrapper around it any more.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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