7
$\begingroup$

OI think that I am committing a basic error that may want to close it, but I am not finding where I am wrong.

This is my code:

r1 = 15; r2 = 8; c = 50; γ = ArcSin[(r1 - r2)/c] // N;
l1 = (2 γ + π) r1
l2 = (π - 2 γ) r2
l3 = 2 c Cos[γ]
L = 2 c Cos[γ] + (2 γ + π) r1 + (π - 2 γ) r2

Here I am creating a graphic:

g=Graphics[{Circle[{0,0},r1,{π/2-γ,((3*π))/2+γ}],
Circle[{c,0},r2,{π/2-γ,-(π/2)+γ}],
Line[{{Cos[π/2-γ]*r1,Sin[π/2-γ]*r1},{Cos[π/2-γ]*r2+c,Sin[π/2-γ]*r2}}],
Line[{{Cos[((3*π))/2+γ]*r1,Sin[((3*π))/2+γ]*r1},{Cos[-(π/2)+γ]*r2+c,Sin[-(π/2)+γ]*r2}}],
PointSize[0.03],
Point[{0,0}],
Point[{c,0}],
PlotRange->{{-100,-100},{100,100}}}]

enter image description here

I want my animation turn in point {0,0}, but something is wrong.

What would it be?

img = Rotate[g, #, {0, 0}] & /@ Range[0, 2 Pi, Pi/6]

Export["Motion.gif", img]
$\endgroup$
1
  • $\begingroup$ -1 for too many fake edits. Namely, edits with the sole purpose of bumping your post on top of the stack of active questions. Also, please refrain doing minor edits on several questions at the same time. Refer to this policy, and for further comments join this meta discussion. $\endgroup$
    – user31159
    Commented Nov 23, 2016 at 15:23

1 Answer 1

14
$\begingroup$

There were some strange characters in your code (/2 as one Unicode code). Might have been caused by copying your code here. Anyway I corrected them here.

The solution to your problem is the use of GeometricTransformation, which you can apply on graphics elements, not a Graphics object as a whole. Therefore, I removed the Graphics part from g and applied GeometricTransformation to it. Rotate is used to rotate any Mathematica object (not only graphics) and is not suited for this task, as its operation is difficult to align with underlying graphics coordinates.

g = {Circle[{0, 0}, r1, {Pi/2 - γ, ((3*Pi))/2 + γ}],     
     Circle[{c, 0}, r2, {Pi/2 - γ, -(Pi/2) + γ}],     
     Line[{{Cos[Pi/2 - γ]*r1, 
      Sin[Pi/2 - γ]*r1}, {Cos[Pi/2 - γ]*r2 + c, 
      Sin[Pi/2 - γ]*r2}}],     Line[{{Cos[((3*Pi))/2 + γ]*r1, 
      Sin[((3*Pi))/2 + γ]*r1}, {Cos[-(Pi/2) + γ]*r2 + c,
       Sin[-(Pi/2) + γ]*r2}}], Dashed, PointSize[0.03],     
     Point[{0, 0}], Point[{c, 0}]};

Graphics[GeometricTransformation[g, RotationMatrix[#]] & /@ Range[0, 2 Pi,Pi/6]]

Mathematica graphics

Exporting to an animation:

Export["D:\\Users\\Sjoerd\\Desktop\\test.gif", 
 Graphics[GeometricTransformation[g, RotationMatrix[#]], 
    PlotRange -> {{-70, 70}, {-70, 70}}] & /@ Range[0, 2 Pi, Pi/20]]

enter image description here

$\endgroup$
3
  • 1
    $\begingroup$ +1, you could also use RotationTransform instead of RotationMatrix. $\endgroup$
    – Greg Hurst
    Commented Sep 19, 2016 at 18:24
  • 1
    $\begingroup$ @ChipHurst Yeah, but RotationMatrix is 4 characters less ;-) $\endgroup$ Commented Sep 19, 2016 at 18:29
  • $\begingroup$ To shorten the code further, one could directly use RotationMatrix /@ Range[0, 2 Pi, Pi/6] as the second argument of GeometricTransform. $\endgroup$
    – user31159
    Commented Nov 9, 2016 at 13:17

Your Answer

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

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