1
$\begingroup$

Here is my code for My Project.

Manipulate[
 Show[ParametricPlot[{r1 Cos[w1 x] + r2  Cos[w2 x], 
    r1 Sin[w1 x] + r2 Sin[w2 x]}, {x, 0, t}, 
   PlotRange -> 10 {{-1, 1}, {-1, 1}}, PlotLegends -> {"Moon"}, 
   AxesLabel -> {"Time"}, PlotStyle -> {Thick, Red}],
  ParametricPlot[{r1 Cos[w1 x], r1 Sin[w1 x]}, {x, 0, t}, 
   PlotLegends -> {"Earth"}],
  Graphics[{PointSize[Large], Blue, 
    Point[{r1 Cos[w1 x], r1 Sin[w1 x]}]}]],
 {{t, 1, "Time"}, 0.01, 10 Pi, 0.01},
 {{w1, 1, "Angular Velocity"}, 0.2, 5, 0.01},
 {{r1, 2, "Radius"}, 0.2, 10, 0.01},
 {{w2, 1, "Moon Angular Velocity"}, 0.2, 5, 0.01},
 {{r2, 2, " Moon Radius"}, 0.2, 10, 0.01}]

What's the problem here?

$\endgroup$
  • 1
    $\begingroup$ Try replacing x with t in in your Point[...] $\endgroup$ – banone Feb 7 at 8:53
  • $\begingroup$ @banone Thanks! Is there any other way to plot point besides using Graphics here $\endgroup$ – kile Feb 7 at 8:58
  • $\begingroup$ You could try ListPlot. It also goes well with Show. $\endgroup$ – banone Feb 7 at 9:06
  • $\begingroup$ @banone how to adjust the size of this point in ListPlot? $\endgroup$ – kile Feb 7 at 12:30
2
$\begingroup$

Two alternative ways to show the moving point:

Use a single ParametricPlot for both curves and show the moving point using Epilog:

Manipulate[ParametricPlot[{{r1 Cos[w1 x], r1 Sin[w1 x]},
    {r1 Cos[w1 x] + r2 Cos[w2 x], r1 Sin[w1 x] + r2 Sin[w2 x]}}, {x, 0, t}, 
   PlotRange -> 10 {{-1, 1}, {-1, 1}}, 
   PlotLegends -> {"Earth", "Moon"}, AxesLabel -> {"Time"}, 
   PlotStyle -> { Automatic, Red}, BaseStyle -> Thick, 
   Epilog -> {PointSize[Large], Blue, Point[{r1 Cos[w1 t], r1 Sin[w1 t]}]}],
 {{t, 1, "Time"}, 0.01, 10 Pi, 0.01},
 {{w1, 1, "Angular Velocity"}, 0.2, 5, 0.01},
 {{r1, 2, "Radius"}, 0.2, 10, 0.01},
 {{w2, 1, "Moon Angular Velocity"}, 0.2, 5, 0.01}, 
 {{r2, 2, " Moon Radius"}, 0.2, 10, 0.01}]

enter image description here

Alternatively, use separate ParametricPlots for earth and moon and use the options MeshFunctions, Mesh and MeshStyle in the first plot to show the moving point:

Manipulate[Show[ParametricPlot[{r1 Cos[w1 x], r1 Sin[w1 x]}, {x, 0, t}, 
    PlotRange -> 10 {{-1, 1}, {-1, 1}}, PlotLegends -> {"Earth"}, 
    AxesLabel -> {"Time"}, BaseStyle -> Thick, 
    MeshFunctions -> {#3 &}, Mesh -> {{t}}, 
    MeshStyle -> Directive[PointSize[Large], Blue]], 
   ParametricPlot[{r1 Cos[w1 x] + r2 Cos[w2 x], r1 Sin[w1 x] + r2 Sin[w2 x]}, {x, 0, t}, 
    PlotLegends -> {"Moon"}, PlotStyle -> Red, BaseStyle -> Thick]],
 {{t, 1, "Time"}, 0.01, 10 Pi, 0.01},
 {{w1, 1, "Angular Velocity"}, 0.2, 5, 0.01},
 {{r1, 2, "Radius"}, 0.2, 10, 0.01},
 {{w2, 1, "Moon Angular Velocity"}, 0.2, 5, 0.01}, 
 {{r2, 2, " Moon Radius"}, 0.2, 10, 0.01}]

same picture

$\endgroup$
  • $\begingroup$ Is there a way to add PlotLegends for Point? $\endgroup$ – kile Feb 8 at 9:37
  • $\begingroup$ @kile, you can add styling directives (Opacity, PointSize, color, etc. ) before Point[...]. $\endgroup$ – kglr Feb 8 at 9:43
  • $\begingroup$ I want an explaination in right side of the graph like what PlotLegends -> {"Earth", "Moon"} did here. For instance, red line means Moon $\endgroup$ – kile Feb 8 at 9:46
  • $\begingroup$ Epilog -> {PointSize[Large], Blue, Point[{r1 Cos[w1 t], r1 Sin[w1 t]}], PlotLegends -> {"Earth"}} is not working $\endgroup$ – kile Feb 8 at 9:51
  • $\begingroup$ @kile, that's a good question. You can not add legends inside Epilog. But you can change the PlotLegends in ParametricPlot to PlotLegends -> LineLegend[{ColorData[97]@1, Red, Blue}, {"Earth", "Moon", "third legend"}, Joined -> {True, True, False}, LegendMarkers -> {None, None, "Point"}] to get the desired result. $\endgroup$ – kglr Feb 8 at 10:31

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.