r = 1
l = 1
m = 1
\[Omega] = 10
g = 9.8
x = r*Cos[\[Omega]*t] + l*Sin[\[Theta][t]] Cos[\[Phi][t]]
y = r*Sin[\[Omega]*t] + l*Sin[\[Theta][t]] Sin[\[Phi][t]]
z = l*Cos[\[Theta][t]]
L = 1/2 m ((D[x, t])^2 + (D[y, t])^2 + (D[z, t])^2) -m*g*z
{\[Theta]s, \[Phi]s} = NDSolveValue[{\!\(
\*SubscriptBox[\(\[PartialD]\), \(t\)]\((\*
SubscriptBox["\[PartialD]",
RowBox[{
SuperscriptBox["\[Theta]", "\[Prime]",
MultilineFunction->None], "[", "t", "]"}]]L)\)\) - \!\(
\*SubscriptBox[\(\[PartialD]\), \(\[Theta][t]\)]L\) == 0, \!\(
\*SubscriptBox[\(\[PartialD]\), \(t\)]\((\*
SubscriptBox["\[PartialD]",
RowBox[{
SuperscriptBox["\[Phi]", "\[Prime]",
MultilineFunction->None], "[", "t", "]"}]]L)\)\) - \!\(
\*SubscriptBox[\(\[PartialD]\), \(\[Phi][t]\)]L\) == 0,
Derivative[1][\[Theta]][0] == 10,
Derivative[1][\[Phi]][0] == 1, \[Theta][0] == 3/4 Pi, \[Phi][0] ==
0}, {\[Theta], \[Phi]}, {t, 0, 3}]
ParametricPlot3D[{r*Cos[\[Omega]*t] +
l*Sin[\[Theta]s[t]] Cos[\[Phi]s[t]],
r*Sin[\[Omega]*t] + l*Sin[\[Theta]s[t]] Sin[\[Phi]s[t]],
l*Cos[\[Theta]s[t]]}, {t, 0, 3}] 【注 到现在出的轨迹图应该是对的....】
point1[t] = {r*Cos[\[Omega]*t], r*Sin[\[Omega]*t], 0}
point2[t] = {r*Cos[\[Omega]*t] + l*Sin[\[Theta]s[t]] Cos[\[Phi]s[t]],
r*Sin[\[Omega]*t] + l*Sin[\[Theta]s[t]] Sin[\[Phi]s[t]],
l*Cos[\[Theta]s[t]]}
a = Table[
Show[Graphics3D[{Red, Thick,
Line[{{{0, 0, 0}, point1[t]}, {point1[t], point2[t]}}]},
PlotRange -> {{-2, 2}, {-2, 2}, {-2, 2}}, ImageSize -> 300],
ParametricPlot3D[{r*Cos[\[Omega]*t] +
l*Sin[\[Theta]s[t]] Cos[\[Phi]s[t]],
r*Sin[\[Omega]*t] + l*Sin[\[Theta]s[t]] Sin[\[Phi]s[t]],
l*Cos[\[Theta]s[t]]}, {t, 0, 3}]], {t, 0, 3, 0.1}];
Animate[a[[i]], {i, 0, 3, 0.1}, AnimationRate -> 300]
Export["Doublependulum.gif", a]
l = 1
m = 1
\[Omega] = 10
g = 9.8
x = r*Cos[\[Omega]*t] + l*Sin[\[Theta][t]] Cos[\[Phi][t]]
y = r*Sin[\[Omega]*t] + l*Sin[\[Theta][t]] Sin[\[Phi][t]]
z = l*Cos[\[Theta][t]]
L = 1/2 m ((D[x, t])^2 + (D[y, t])^2 + (D[z, t])^2) -m*g*z
{\[Theta]s, \[Phi]s} = NDSolveValue[{\!\(
\*SubscriptBox[\(\[PartialD]\), \(t\)]\((\*
SubscriptBox["\[PartialD]",
RowBox[{
SuperscriptBox["\[Theta]", "\[Prime]",
MultilineFunction->None], "[", "t", "]"}]]L)\)\) - \!\(
\*SubscriptBox[\(\[PartialD]\), \(\[Theta][t]\)]L\) == 0, \!\(
\*SubscriptBox[\(\[PartialD]\), \(t\)]\((\*
SubscriptBox["\[PartialD]",
RowBox[{
SuperscriptBox["\[Phi]", "\[Prime]",
MultilineFunction->None], "[", "t", "]"}]]L)\)\) - \!\(
\*SubscriptBox[\(\[PartialD]\), \(\[Phi][t]\)]L\) == 0,
Derivative[1][\[Theta]][0] == 10,
Derivative[1][\[Phi]][0] == 1, \[Theta][0] == 3/4 Pi, \[Phi][0] ==
0}, {\[Theta], \[Phi]}, {t, 0, 3}]
ParametricPlot3D[{r*Cos[\[Omega]*t] +
l*Sin[\[Theta]s[t]] Cos[\[Phi]s[t]],
r*Sin[\[Omega]*t] + l*Sin[\[Theta]s[t]] Sin[\[Phi]s[t]],
l*Cos[\[Theta]s[t]]}, {t, 0, 3}] 【注 到现在出的轨迹图应该是对的....】
point1[t] = {r*Cos[\[Omega]*t], r*Sin[\[Omega]*t], 0}
point2[t] = {r*Cos[\[Omega]*t] + l*Sin[\[Theta]s[t]] Cos[\[Phi]s[t]],
r*Sin[\[Omega]*t] + l*Sin[\[Theta]s[t]] Sin[\[Phi]s[t]],
l*Cos[\[Theta]s[t]]}
a = Table[
Show[Graphics3D[{Red, Thick,
Line[{{{0, 0, 0}, point1[t]}, {point1[t], point2[t]}}]},
PlotRange -> {{-2, 2}, {-2, 2}, {-2, 2}}, ImageSize -> 300],
ParametricPlot3D[{r*Cos[\[Omega]*t] +
l*Sin[\[Theta]s[t]] Cos[\[Phi]s[t]],
r*Sin[\[Omega]*t] + l*Sin[\[Theta]s[t]] Sin[\[Phi]s[t]],
l*Cos[\[Theta]s[t]]}, {t, 0, 3}]], {t, 0, 3, 0.1}];
Animate[a[[i]], {i, 0, 3, 0.1}, AnimationRate -> 300]
Export["Doublependulum.gif", a]