課題

8.2 アニメーション

imagePoints=Import["D:\\実験1\\star\\star.csv"]

pointsX:=imagePoints[[All,1]]
pointsY:=imagePoints[[All,2]]
(*フーリエ変換*)
Fx :=Fourier[pointsX]
Fy:=Fourier[pointsY]
(*項数の制限*)
nTerms = 50

(*振幅と位相の計算*)
n:=Length[Fx]
ampsX :=Abs[Fx]/n
phasesX := Arg[Fx]
freqsX := Range[0, n-1]

ampsY := Abs[Fy]/n
phasesY := Arg[Fy]
freqsY := Range[0, n-1]
(*三角関数の式計算*)
xExpr[t_] =Sum[ampsX[[k]] Cos[freqsX[[k]]t+phasesX[[k]]],{k,1,Min[nTerms, n]}]
yExpr[t_]=Sum[ampsY[[k]] Cos[freqsY[[k]]t+phasesY[[k]]],{k,1,Min[nTerms, n]}]

Plot[{xExpr[t],yExpr[t]},{t, 0,2Pi}]
dots={ Red,PointSize[0.01],Point[imagePoints]}
Graphics[{dots}]
animation =Animate[
Module[{mainPlot, xPlot, yPlot, currentX, currentY},
currentX = xExpr[t];
currentY = yExpr[t];
options= {AspectRatio->1, PlotRange->{{0,1}, {0,1}}};
mainPlot=Graphics[{{Blue, Disk[{xExpr[t], yExpr[t]}, 0.02]},
{Red,Line[Table[{xExpr[s],yExpr[s]},{s,0,t,t/100}]]},
{Blue, Line[{{currentX, currentY},{currentX, 1}}]},
{Blue, Line[{{currentX, currentY},{-0.2, currentY}}]}
}, options];
xPlot = Rotate[Plot[xExpr[t+s],{s, 0, 2Pi}, 
PlotRange->{{0,2Pi},{0, 1}},
AspectRatio->2
], -90 Degree];
yPlot = Plot[yExpr[t+s], {s, 0, 2Pi},
PlotRange->{{0,2Pi},{0,1}},
AspectRatio->2];
Grid[{
{SpanFromLeft, xPlot},
{yPlot, mainPlot}
},Spacings->0]
],
{t,0,2Pi, Pi/50}]