FIZ353 - Numerical Analysis | 20/11/2020
Emre S. Tasci emre.tasci@hacettepe.edu.tr
Consider an ideal spring attached to a body, on a frictionless surface. What else can we ask! Here is how it will look like:
import numpy as np
import matplotlib.pyplot as plt
k = 10 # N/m Spring constant
m = 1 # kg # Mass
A = 5 # cm - Amplitude
w = np.sqrt(k/m) # Frequency
N = 50 # Number of observations
t = np.linspace(0,20,N)
x = A*np.cos(w*t)
tt = np.linspace(0,20,1000)
xx = A*np.cos(w*tt)
plt.plot(tt,xx,"r-")
plt.plot(t,x,"ob")
plt.xlabel("t (s)")
plt.ylabel("x (m)")
plt.yticks(np.arange(-5,6))
plt.title("Position vs. Time")
plt.grid(axis='y')
plt.show()
So, the harmonic motion is obvious. But keep in mind that this is the position vs. time graph. If we were to record the motion of the body using a camera placed on top, we would observe something like:
plt.plot(np.zeros((N,1)),x,"ob")
plt.show()
Which, obviously, is just the projection of the "x vs. t" graph unto the x axis (do please verify that this is indeed the case).
## A print script to feed into CalcPlot3d -- Nevermind 8)
## (https://www.monroecc.edu/faculty/paulseeburger/calcnsf/CalcPlot3D/)
#for i in x:
# print(" <point>\n point=\"(%.4f,0,0)\"\n color=\"rgb(0,0,255)\"\n size=\"4\" \n visible=\"true\"\n </point>\n"%(i))
Go on and just play with the interactable plot below (obtained using CalcPlot3D's wonderful scripting options)
from IPython.display import HTML
HTML('<iframe frameborder="0" height="480px" src="https://c3d.libretexts.org/CalcPlot3D/dynamicFigure/'\
+'index.html?type=point;point=(5.0000,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(1.3821,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.2359,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-3.7239,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(2.1771,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.9275,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(0.5470,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.6251,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-3.1040,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(2.9091,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.7123,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-0.3039,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.8803,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-2.3942,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(3.5567,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.3605,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-1.1460,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.9940,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-1.6149,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.1012,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(3.8823,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-1.9549,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.9631,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-0.7889,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.5269,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(3.2916,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-2.7072,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.7882,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(0.0600,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.8214,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(2.6055,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-3.3810,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.4747,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(0.9072,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.9762,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(1.8439,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-3.9568,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.0314,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(1.7280,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.9868,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(1.0289,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.4179,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-3.4713,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(2.4988,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.8528,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(0.1840,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.7511,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-2.8106,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(3.1972,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.5782,0,0);visible=true;color=rgb(0,0,255);size=4&type=window;hsrmode=3;nomidpts=true;anaglyph=-1;center=0,0,-1,1;focus=0,0,0,1;up=1,0,0,1;transparent=false;alpha=140;twoviews=false;unlinkviews=false;axisextension=0.7;xaxislabel=x;yaxislabel=y;zaxislabel=z;edgeson=true;faceson=false;showbox=false;showaxes=true;showticks=true;perspective=false;centerxpercent=0.5170894526034712;centerypercent=0.4912280701754386;rotationsteps=30;autospin=true;xygrid=false;yzgrid=false;xzgrid=false;gridsonbox=true;gridplanes=false;gridcolor=rgb(128,128,128);xmin=-5;xmax=5;ymin=-2;ymax=2;zmin=-2;zmax=2;xscale=1;yscale=1;zscale=1;zcmin=-4;zcmax=4;zoom=0.45;xscalefactor=1;yscalefactor=1;zscalefactor=1'\
+' width="90%">')
When the camera is recording the motion of the body, it doesn't have a reference for the axis or whatsoever. What it sees is something like this:
HTML('<iframe frameborder="0" height="480px" src="https://c3d.libretexts.org/CalcPlot3D/dynamicFigure/'\
+'index.html?type=point;point=(5.0000,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(1.3821,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.2359,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-3.7239,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(2.1771,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.9275,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(0.5470,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.6251,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-3.1040,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(2.9091,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.7123,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-0.3039,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.8803,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-2.3942,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(3.5567,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.3605,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-1.1460,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.9940,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-1.6149,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.1012,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(3.8823,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-1.9549,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.9631,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-0.7889,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.5269,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(3.2916,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-2.7072,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.7882,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(0.0600,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.8214,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(2.6055,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-3.3810,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.4747,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(0.9072,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.9762,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(1.8439,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-3.9568,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.0314,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(1.7280,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.9868,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(1.0289,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.4179,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-3.4713,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(2.4988,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.8528,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(0.1840,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.7511,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-2.8106,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(3.1972,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.5782,0,0);visible=true;color=rgb(0,0,255);size=4&type=window;hsrmode=3;nomidpts=true;anaglyph=-1;center=0,0,-1,1;focus=0,0,0,1;up=1,0,0,1;transparent=false;alpha=140;twoviews=false;unlinkviews=false;axisextension=0.7;xaxislabel=x;yaxislabel=y;zaxislabel=z;edgeson=true;faceson=false;showbox=false;showaxes=false;showticks=true;perspective=false;centerxpercent=0.5170894526034712;centerypercent=0.4912280701754386;rotationsteps=30;autospin=true;xygrid=false;yzgrid=false;xzgrid=false;gridsonbox=true;gridplanes=false;gridcolor=rgb(128,128,128);xmin=-5;xmax=5;ymin=-2;ymax=2;zmin=-2;zmax=2;xscale=1;yscale=1;zscale=1;zcmin=-4;zcmax=4;zoom=0.45;xscalefactor=1;yscalefactor=1;zscalefactor=1'\
+' width="90%">')
And it (the camera) could have been oriented in any unfortunate angle -- such as looking from the diagonal, like:
from IPython.display import HTML
HTML('<iframe frameborder="0" height="480px" src="https://c3d.libretexts.org/CalcPlot3D/dynamicFigure/'\
+'index.html?type=point;point=(5.0000,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(1.3821,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.2359,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-3.7239,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(2.1771,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.9275,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(0.5470,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.6251,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-3.1040,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(2.9091,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.7123,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-0.3039,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.8803,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-2.3942,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(3.5567,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.3605,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-1.1460,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.9940,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-1.6149,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.1012,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(3.8823,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-1.9549,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.9631,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-0.7889,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.5269,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(3.2916,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-2.7072,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.7882,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(0.0600,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.8214,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(2.6055,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-3.3810,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.4747,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(0.9072,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.9762,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(1.8439,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-3.9568,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.0314,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(1.7280,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.9868,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(1.0289,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.4179,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-3.4713,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(2.4988,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.8528,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(0.1840,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.7511,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-2.8106,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(3.1972,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.5782,0,0);visible=true;color=rgb(0,0,255);size=4&type=window;hsrmode=3;nomidpts=true;anaglyph=-1;center=2,1,1,1;focus=0,0,0,1;up=0,1,0,1;transparent=false;alpha=140;twoviews=false;unlinkviews=false;axisextension=0.7;xaxislabel=x;yaxislabel=y;zaxislabel=z;edgeson=true;faceson=false;showbox=false;showaxes=false;showticks=true;perspective=false;centerxpercent=0.5170894526034712;centerypercent=0.4912280701754386;rotationsteps=30;autospin=true;xygrid=false;yzgrid=false;xzgrid=false;gridsonbox=true;gridplanes=false;gridcolor=rgb(128,128,128);xmin=-5;xmax=5;ymin=-2;ymax=2;zmin=-2;zmax=2;xscale=1;yscale=1;zscale=1;zcmin=-4;zcmax=4;zoom=0.45;xscalefactor=1;yscalefactor=1;zscalefactor=1'\
+' width="90%">')
or, even worse:
from IPython.display import HTML
HTML('<iframe frameborder="0" height="480px" src="https://c3d.libretexts.org/CalcPlot3D/dynamicFigure/'\
+'index.html?type=point;point=(5.0000,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(1.3821,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.2359,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-3.7239,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(2.1771,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.9275,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(0.5470,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.6251,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-3.1040,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(2.9091,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.7123,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-0.3039,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.8803,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-2.3942,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(3.5567,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.3605,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-1.1460,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.9940,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-1.6149,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.1012,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(3.8823,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-1.9549,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.9631,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-0.7889,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.5269,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(3.2916,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-2.7072,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.7882,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(0.0600,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.8214,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(2.6055,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-3.3810,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.4747,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(0.9072,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.9762,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(1.8439,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-3.9568,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.0314,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(1.7280,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.9868,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(1.0289,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.4179,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-3.4713,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(2.4988,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.8528,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(0.1840,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-4.7511,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(-2.8106,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(3.1972,0,0);visible=true;color=rgb(0,0,255);size=4&type=point;point=(4.5782,0,0);visible=true;color=rgb(0,0,255);size=4&type=window;hsrmode=3;nomidpts=true;anaglyph=-1;'\
+'center=1,0.01,0,1;focus=0,0,0,1;up=0,0,1,1;transparent=false;alpha=140;twoviews=false;unlinkviews=false;axisextension=0.7;xaxislabel=x;yaxislabel=y;zaxislabel=z;edgeson=true;faceson=false;'\
+'showbox=false;showaxes=false;showticks=true;perspective=false;centerxpercent=0.5170894526034712;centerypercent=0.4912280701754386;rotationsteps=30;autospin=true;xygrid=false;yzgrid=false;xzgrid=false;gridsonbox=true;gridplanes=false;gridcolor=rgb(128,128,128);xmin=-5;xmax=5;ymin=-2;ymax=2;zmin=-2;zmax=2;xscale=1;yscale=1;zscale=1;zcmin=-4;zcmax=4;zoom=0.45;xscalefactor=1;yscalefactor=1;zscalefactor=1'\
+' width="90%">')
(interact with each of the "axeless" graphs to assure that they are indeed the same points, albeit viewed from different angles)
The data recorded by the camera is dependent on what it sees, with respect to its x & y axes.
Now, we are going to suppose that, since we didn't know the system, we arbitrarily placed three cameras, like the ones shown in Shlen's examplary paper.
def Rx(gamma):
Rx = np.array([[1,0,0],\
[0,np.cos(gamma),-np.sin(gamma)],\
[0,np.sin(gamma),np.cos(gamma)]])
return Rx
def Ry(beta):
Ry = np.array([[np.cos(beta),0,np.sin(beta)],\
[0,1,0],\
[-np.sin(beta),0,np.cos(beta)]])
return Ry
def Rz(alpha):
Rz = np.array([[np.cos(alpha),-np.sin(alpha),0],\
[np.sin(alpha),np.cos(alpha),0],\
[0,0,1]])
return Rz
def RzRyRx(alpha,beta,gamma):
return np.linalg.multi_dot((Rz(alpha),Ry(beta),Rx(gamma)))
Rx(np.pi)
RzRyRx(0,0,np.pi)
If we are to transform (rotate) our data points in 3D, we need our points to be defined in 3D:
data3D = np.zeros((N,3))
for i in np.arange(N):
data3D[i,0] = x[i]
#print(data3D)
This is our most convenient view of the data, as seen along the z-axis, with the x-axis being the horizontal and y-axis being the vertical.
plt.plot(data3D[:,0],data3D[:,1],"ob")
plt.title("Perfect View (along the z-axis)")
plt.xlabel("x axis")
plt.ylabel("y axis")
plt.show()
Now, we are going to rotate our camera around the y-axis for 90° degrees such that we are looking along the x-axis (and kudos to those of you who thought "but this transformation operation is about the rotation of the points, not the axes" -- fortunately, for this case, the two interpretations don't differ very much in perception ;)
data3Dp = np.linalg.multi_dot((Ry(np.deg2rad(90)),data3D[:,:].T)).T
plt.plot(data3Dp[:,0],data3Dp[:,1],"ob")
plt.title("View along the x-axis")
plt.xlabel("Camera's x-axis")
plt.ylabel("Camera's y-axis")
plt.show()
It seems just about the same as looking along the z-axis until you see the order of range at the bottom (x10-16)... So, this is what it actully looks like when you equate the range to that of the z-axis view:
plt.plot(data3Dp[:,0],data3Dp[:,1],"ob")
plt.title("View along the x-axis - Range fixed")
plt.xlabel("Camera's x-axis")
plt.ylabel("Camera's y-axis")
plt.axis(([-5,5,-0.05,0.05]))
plt.show()
...and here are the three in one graph:
plt.subplot(3,1,1)
plt.plot(data3D[:,0],data3D[:,1],"ob")
plt.title("Perfect View (along the z-axis)")
plt.xlabel("Camera's x-axis")
plt.ylabel("Camera's y-axis")
plt.subplot(3,1,2)
plt.plot(data3Dp[:,0],data3Dp[:,1],"ob")
plt.title("View along the x-axis")
plt.xlabel("Camera's x-axis")
plt.ylabel("Camera's y-axis")
plt.subplot(3,1,3)
plt.plot(data3Dp[:,0],data3Dp[:,1],"ob")
plt.title("View along the x-axis - Range fixed")
plt.xlabel("Camera's x-axis")
plt.ylabel("Camera's y-axis")
plt.axis(([-5,5,-0.05,0.05]))
plt.subplots_adjust(hspace=3)
plt.show()
# Camera A data:
data3D_A = np.linalg.multi_dot((Rz(np.deg2rad(80)),Rx(np.deg2rad(20)),data3D[:,:].T)).T
plt.plot(data3D_A[:,0],data3D_A[:,1],"ob")
plt.title("Camera A")
plt.xlabel("Camera A's x-axis")
plt.ylabel("Camera A's y-axis")
plt.axis(([-5,5,np.min(data3D_A[:,1])*1.1,np.max(data3D_A[:,1])*1.1]))
plt.show()
# Camera B data:
data3D_B = np.linalg.multi_dot((Ry(np.deg2rad(20)),Rz(np.deg2rad(100)),data3D[:,:].T)).T
plt.plot(data3D_B[:,0],data3D_B[:,1],"ob")
plt.title("Camera B")
plt.xlabel("Camera B's x-axis")
plt.ylabel("Camera B's y-axis")
plt.axis(([-5,5,np.min(data3D_B[:,1])*1.1,np.max(data3D_B[:,1])*1.1]))
plt.show()
# Camera C data:
data3D_C = np.linalg.multi_dot((Rz(np.deg2rad(60)),Rx(np.deg2rad(160)),Rz(np.deg2rad(180)),data3D[:,:].T)).T
plt.plot(data3D_C[:,0],data3D_C[:,1],"ob")
plt.title("Camera C")
plt.xlabel("Camera C's x-axis")
plt.ylabel("Camera C's y-axis")
plt.axis(([-5,5,np.min(data3D_C[:,1])*1.1,np.max(data3D_C[:,1])*1.1]))
plt.show()
data_all = np.array([data3D_A[:,0],data3D_A[:,1],
data3D_B[:,0],data3D_B[:,1],
data3D_C[:,0],data3D_C[:,1]])
#data_all = np.array([data3D_C[:,0],data3D_C[:,1],
# data3D_B[:,0],data3D_B[:,1],
# data3D_A[:,0],data3D_A[:,1]])
print(data_all[:,0:3])
print(data3D_A[0,:])
print(data3D_B[1,:])
print(data3D_C[2,:])
S = np.dot(data_all,data_all.T)/(N-1)
with np.printoptions(formatter={'float': '{:9.5f}'.format}):
print(S)
#Sigma = np.cov(data_all)
#print(Sigma)
[u,s,vh]=np.linalg.svd(S)
with np.printoptions(formatter={'float': '{:9.5f}'.format}):
print(u,"\n\n",s,"\n\n",vh)
u1=u[:,0]
with np.printoptions(formatter={'float': '{:9.5f}'.format}):
print("u1: ",u1,"\n")
print(np.dot(u1.T,data_all))
m = np.mean(data_all,1)
print(m)
data_all_norm = data_all.copy()
for i in np.arange(6):
data_all_norm[i,:] -= m[i]
print(data_all[:,0:3])
print(data_all_norm[:,0:3])
S = np.dot(data_all_norm,data_all_norm.T)/(N-1)
with np.printoptions(formatter={'float': '{:9.5f}'.format}):
print(S)
#Sigma = np.cov(data_all_norm)
#print(Sigma)
[u,s,vh]=np.linalg.svd(S)
u*=-1
print(u,"\n\n",s,"\n\n",vh)
u1=u[:,0]
print(u1)
for i in [0,2,4]:
print(u1[i+1]/u1[i])
plt.plot(data_all_norm[0,:],data_all_norm[1,:],"bo")
xx = np.linspace(-5,5,N)
yy = u1[1]/u1[0]*xx
plt.plot(xx,yy,"r-")
plt.show()
plt.plot(data_all_norm[2,:],data_all_norm[3,:],"bo")
xx = np.linspace(-5,5,N)
yy = u1[3]/u1[2]*xx
plt.axis([-5,5,np.min(data_all_norm[3,:])*1.1,np.max(data_all_norm[3,:])*1.1])
plt.plot(xx,yy,"r-")
plt.show()
plt.plot(data_all_norm[4,:],data_all_norm[5,:],"bo")
xx = np.linspace(-5,5,N)
yy = u1[5]/u1[4]*xx
plt.axis([-5,5,np.min(data_all_norm[5,:])*1.1,np.max(data_all_norm[5,:])*1.1])
plt.plot(xx,yy,"r-")
plt.show()
print(u1)
print(data_all_norm.shape)
res=np.dot(u.T,data_all_norm)
res.shape
with np.printoptions(formatter={'float': '{:7.3f}'.format}):
print(res[:,0:8])
plt.plot(res[0,:],np.zeros(N),"r+")
for i in range(1,6):
plt.plot(res[i,:],np.ones(N)*0.001*i,"go")
plt.plot(x,np.ones(N)*0.006,"bx")
plt.show()
np.var(res[0,:])
with np.printoptions(formatter={'float': '{:7.3f}'.format}):
print(np.diagonal(np.cov(data_all_norm)))
np.var(x)
tt = np.linspace(0,20,1000)
xx = A*np.cos(w*tt)
plt.plot(tt,xx,"r-")
plt.plot(t,x,"ob")
plt.xlabel("t (s)")
plt.ylabel("x (m)")
plt.yticks(np.arange(-5,6))
plt.title("Position vs. Time (Essential)")
plt.grid(axis='y')
plt.show()
plt.title("Position vs. Time (Camera A - x)")
plt.plot(data_all_norm[0,:],"bx-")
plt.show()
plt.title("Position vs. Time (Camera A - y)")
plt.plot(data_all_norm[1,:],"bx-")
plt.show()
plt.title("Position vs. Time (PCA)")
plt.plot(res[0,:],"rx-")
plt.show()
plt.plot(data_all_norm[0,:],"bx-",res[0,:],"rx-",x,"go")
plt.show()
plt.plot(data3D_A[:,0],"rx")
plt.show()