4
$\begingroup$

I want

  • to connect the 3 red dots
  • to make the red dots depicted on the sinusoidal circular rather than elliptical.
  • to make these 3 canvas are properly scaled such that joining lines are parallel to horizontal and vertical axes.

enter image description here

Manipulate[
 GraphicsGrid[{
   {
    Graphics[{
      {Red, Disk[{Cos[t], Sin[t]}, 0.05]},
      {Dashed, Blue, Line[{{0, 0}, {Cos[t], Sin[t]}}]},
      {Dashed, Gray, Circle[{0, 0}, 1]}
      }, PlotRange -> {{-1.2, 1.2}, {-1.2, 1.2}}, Axes -> True, 
     AspectRatio -> 1],
    Show[
     Graphics[{
       {Red, Dashed, Line[{{t, 0}, {t, Sin[t]}}]},
       {Red, Dashed, Line[{{0, Sin[t]}, {t, Sin[t]}}]},
       {Red, Disk[{t, Sin[t]}, 0.09]}
       }],
     Plot[Sin[x], {x, 0, t}]
     , PlotRange -> {{-0, 2 \[Pi]}, {-1.2, 1.2}}, Axes -> True, 
     AspectRatio -> 1, AxesLabel -> {"t", "Sin[t]"}]
    }, {
    Rotate[Show[
      Graphics[{
        {Red, Dashed, Line[{{t, 0}, {t, Cos[t]}}]},
        {Red, Dashed, Line[{{0, Cos[t]}, {t, Cos[t]}}]},
        {Red, Disk[{t, Cos[t]}, 0.09]}
        }],
      Plot[Cos[x], {x, 0, t}]
      , PlotRange -> {{-0, 2 \[Pi]}, {-1.2, 1.2}}, Axes -> True, 
      AspectRatio -> 1, AxesLabel -> {"t", "Cos[t]"}], -\[Pi]/2]
    }
   }],
 {t, 0.001, 2 \[Pi]}]
$\endgroup$
  • $\begingroup$ Is it impossible? If yes, I will delete this question shortly. Thank you! $\endgroup$ – Money Oriented Programmer Sep 3 at 10:52
  • $\begingroup$ something like this? $\endgroup$ – kglr Sep 3 at 11:23
  • 1
    $\begingroup$ for Q2: replace {Red, Disk[{t, Sin[t]}, 0.09]} with {Red, AbsolutePointSize[7], Point[{t, Sin[t]}]}; similarly for the other disk. $\endgroup$ – kglr Sep 3 at 11:25
  • $\begingroup$ @kglr: Thank you! $\endgroup$ – Money Oriented Programmer Sep 3 at 11:27
  • $\begingroup$ "Is it impossible? If yes, I will delete this question shortly." That should not be a reason for deleting. Please keep it. $\endgroup$ – Szabolcs Sep 3 at 13:10
4
$\begingroup$

enter image description here

Q2. To prevent disks from appearing as ellipses you can

  1. Specify the radius as Offset[r] in absolute units. That is,

 {Red, Disk[{t, Cos[t]}, Offset[4]]}

and

 {Red, Disk[{t, Sin[t]}, Offset[4]]}
  1. Use Point instead of Disk: e.g.,

 {Red, AbsolutePointSize[7], Point[{t, Sin[t]}]}

Q3: Use the same ImageSize in all three plots (adding invisible axes labels where missing to prevent different automatic resizing caused by different sized labels)

Q1: It may be possible to do it without abandoning GraphicsGrid ... but an alternative approach using a single plot with all the desired elements is possible:

Without the axes we can get the three plots in a single ParametricPlot:

Manipulate[ParametricPlot[{{Cos[x], Sin[x]}, {2 + x, Sin[x]}, {Cos[x], -2 - x}}, 
   {x, 0, t},
   MeshFunctions -> {#3 &}, 
   Mesh -> {{t}}, 
   MeshStyle -> Directive[Red, PointSize[Large]], 
   PlotStyle -> Thick, 
   PlotRange -> {{-3/2, 2 + 2 Pi}, {-2 - 2 Pi, 3/2}}, 
   Axes -> False, 
   ImageSize -> 300, 
   PlotRangePadding -> Scaled[.03], 
   ImagePadding -> 20, 
   PlotRangeClipping -> False,
   Prolog -> {Thick, Dashed, Green, Line[{{0, 0}, {Cos[t], Sin[t]}}], 
     EdgeForm[Dashed], FaceForm[Opacity[.2, Yellow]], 
      Polygon[{{Cos[t], Sin[t]}, {2 + t, Sin[t]}, {Cos[t], -2 - t}}]}, ], 
 {{t, Pi/3}, 0.01, 2 Pi}]

enter image description here

To add the three axes we need to construct graphics primitives that look like axes:

ClearAll[axisFunc]
axisFunc[tl1_: 5, tl2_: 5, to_: - 25][a_, b_, start_, end_, z_, 
   dir : (Horizontal | Vertical)] := 
  Module[{f = dir /. {Horizontal -> Identity, Vertical -> Reverse}, 
     p = dir /. {Horizontal -> 1, Vertical -> 2}}, 
  {Text[Style[#[[p]] If[a < b, 1, -1], 10], Offset[f@{0, to/p}, 
     MapAt[Rescale[#, {a, b}, {a + start, b + end}] &, #, {p}]], {0, 0}] & /@ 
     (If[tl1 > 0 && tl2 > 0, Rest@#, #] &@ Thread[f@{Subdivide[a, b, 3], z}]),
    Thin, Line[{f@{#, z}, f@{#2, z}}] & @@ {a + start, b + end}, 
    Line[{Offset[f@{0, -tl1}, #], Offset[f@{0, tl2}, #]}] & /@ 
     Thread[f@{Subdivide[a + start, b + end, 3], z}],
    Line[{Offset[f@{0, -tl1/2}, #], Offset[f@{0, tl2/2}, #]}] & /@ 
     Thread[f@{Complement[Subdivide[a + start, b + end, 9], 
         Subdivide[a + start, b + end, 3]], z}]}];

We use axisFunc with different parameters to construct the axes to be added to the Prolog option setting:

axes = {axisFunc[5, 5, -10][0, 2 Pi, 2, 2, 0, Horizontal], 
   axisFunc[10, 0, 10][-1, 1, 0, 0, -2, Horizontal], 
   axisFunc[][0, -2 Pi, -2, -2, 0, Vertical], 
   axisFunc[0, 10, -15][-1, 1, 0, 0, 2, Vertical]};

axeslabels = {Text[Style[TraditionalForm[Sin[θ]], 15, Black], {1.4, 0}, {0, 0}, {0, 1}], 
   Text[Style[TraditionalForm[Cos[θ]], 15, Black], {0, -1.4}, {0, 0}], 
   Text[Style[TraditionalForm[θ], 15, Black], {2.3 + 2 Pi,  0}, {0, 0}], 
   Text[Style[TraditionalForm[θ], 15, Black], {0, -2.3 - 2 Pi}, {0, 0}]};

Manipulate[ParametricPlot[{{Cos[x], Sin[x]}, {2 + x, Sin[x]}, {Cos[x], -2 - x}}, 
  {x, 0, t}, 
  MeshFunctions -> {#3 &}, 
  Mesh -> {{t}}, 
  MeshStyle -> Directive[Red, PointSize[Large]], 
  PlotStyle -> Thick, 
  PlotRange -> {{-3/2, 2 + 2 Pi}, {-2 - 2 Pi, 3/2}},
  Axes -> False, 
  ImageSize -> 400, 
  PlotRangePadding -> Scaled[.03], 
  ImagePadding -> 20, 
  PlotRangeClipping -> False
  Prolog -> {axes, axeslabels, Dashed, Thick, Red,  
    Line[{{0, -2 - t}, {Cos[t], -2 - t}}], Line[{{2 + t, Sin[t]}, {2 + t, 0}}], 
    Green, Line[{{0, 0}, {Cos[t], Sin[t]}}], EdgeForm[Dashed], 
    FaceForm[Opacity[.2, Yellow]], 
    Polygon[{{Cos[t], Sin[t]}, {2 + t, Sin[t]}, {Cos[t], -2 - t}}]},], 
 {{t, Pi/3}, 0.01, 2 Pi}]

enter image description here

Replace Manipulate[stuff, {{t, Pi/3}, 0.01, 2 Pi}] with

frames = Table[stuff, {t,  0.01, 2 Pi, 2 Pi/100}];

and Export frames as GIF file to get the animation at the top.

$\endgroup$
  • $\begingroup$ How about drawing across grid cells? Is it impossible? $\endgroup$ – Money Oriented Programmer Sep 3 at 11:31
  • $\begingroup$ @WellHarassedProgrammer, I will update if I can make the approach in this answer work for this case. $\endgroup$ – kglr Sep 3 at 11:33
  • $\begingroup$ Just seems much easier to dispense with GraphicsGrid and integrate the three plots into one plot that looks like three separate plots then can easily draw lines between the points. $\endgroup$ – Dominic Sep 3 at 11:43
  • $\begingroup$ @Dominic, that's what i did in the linked post. Getting the three axes right is a bit chore. $\endgroup$ – kglr Sep 3 at 11:46
  • 1
    $\begingroup$ @WellHarassedProgrammer, Use the same image size in all three graphs. (also need to make adjustments for the different axes labels) $\endgroup$ – kglr Sep 3 at 12:56

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.