TransWikia.com

Moving a circle on a function

Mathematica Asked by Matandra on February 16, 2021

I’m trying to write a code that moves a circle on the graph of a specific function, but I can’t find the error in my code. I added values to both coordinates, but the Manipulate fails to count the value from the formula. I’m moving the circle with a vector that is perpendicular to the function, and the length of the vector is 1 because the radius of the circle is also 1.
How do I solve this problem? I’m a beginner.

f1[x_] := x
Manipulate[
 Show[
  Plot[f1, {x, -1, 8},  AspectRatio -> Automatic],
  ParametricPlot[
   {Cos[x] - Sqrt[1/((f1'[t])^2 + 1)]*f1'[t] + t, 
    Sin[x] + Sqrt[1/((f1'[t])^2 + 1)]}, {x, 0, 2 Pi}, 
   PlotRange -> {{-4, 4}, {-4, 4}}
   ]
  ], {t, 0, 2 Pi}
 ]

One Answer

Use your function to define a parametric curve (say, curve) and use it with ParametricPlot and add the moving circle asEpilog. The normal to the curve at point t is Cross[Normalize[curve'[t]]] so we can easily find the center of moving circle:

ClearAll[curve]
curve[x_] := {x, x}

Manipulate[ParametricPlot[curve[x], {x, -Pi, 3 Pi}, 
  Epilog -> {Red, Circle[curve[t] + Cross[Normalize[curve'[t]]]]}, 
  PlotRange -> {{-Pi, 3 Pi}, {-Pi, 3 Pi}}, 
  PlotRangePadding -> Scaled[.1]], 
{{t, 0}, -Pi, 3 Pi, Appearance -> "Open"}]

enter image description here

ClearAll[curve2]
curve2[x_] := 5 {Cos @ x, Sin @ x};

Manipulate[ParametricPlot[curve2[x], {x, 0, 2 Pi}, 
  Epilog -> {Red, Circle[curve2[t] + Cross[Normalize[curve2'[t]]]]}, 
  PlotRange -> 5 {{-1, 1}, {-1, 1}}, 
  PlotRangePadding -> Scaled[.1]], 
{{t, 0.}, 0., 2. Pi, Appearance -> "Open"}]

enter image description here

ClearAll[curve3]
curve3[x_] := 7 {Sin[4 Sin @ x], Sin[4 Cos @ x]};

frames = Table[ParametricPlot[curve3[x], {x, 0, 2 Pi}, PlotStyle -> Thick, 
    Epilog -> {Red, Thick, Circle[curve3[t] + Cross[Normalize[curve3'[t]]]]}, 
    PlotRange -> 7 {{-1, 1}, {-1, 1}}, 
    PlotRangePadding -> Scaled[.15], ImageSize -> Large, 
    Axes -> False], {t, 0., 2  Pi, 2 Pi/100}];

Export["circleoncurve.gif", frames]

enter image description here

Use Circle[curve3[t] - Cross[Normalize[curve3'[t]]]] to place the circle outside the curve:

enter image description here

Answered by kglr on February 16, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP