01.3 Coordinate Transformations

The position vector of a point in space depends on how you define your coordinate system.

Suppose that one coordinate system $S$ defined by $(x,y,z)$ is fixed at the origin. Suppose that a second coordinate system $S_0$ is defined by axes labeled $(x_0,y_0,z_0)$ with origin at the location $\Delta \vec{r}$ relative to the first frame.

A particle is at the location $\vec{r}$ relative to the fixed frame. Relative to the second frame, its location is $\vec{r}_0$. These vectors are related according to

$$\vec{r}=\Delta \vec{r} + \vec{r}_0.$$

Drawing two coordinate systems in iVisual

Suppose that the first frame $S$ is at the origin (or defines the origin). The second frame $S_0$ is aligned with the first frame and is at the location $<1.1,0,0>$ m. An object is at $\vec{r}=<2,0.5,0>$ m relative to the first frame. What is the object's position relative to the second frame, $\vec{r}_0$? Sketch the two frames, sketch $\vec{r}$ and $\vec{r}_0$.


In [1]:
#import packages
from __future__ import division, print_function
from ivisual import *



In [2]:
#create the scene
scene = canvas(title='Linear Coordinate Transformation')
 
#draw first coordinate system
L=1
sw=L/50
xaxis=arrow(pos=(-L/2,0,0), axis=(L,0,0), shaftwidth=sw)
yaxis=arrow(pos=(0,-L/2,0), axis=(0,L,0), shaftwidth=sw)
zaxis=arrow(pos=(0,0,-L/2), axis=(0,0,L), shaftwidth=sw)
 
#dr is the position of the second coordinate system relative to the first
dr=1.1*vector(1,0,0)
drarrow=arrow(pos=(0,0,0),axis=dr, shaftwidth=2*sw, fixedwidth=True,  color=color.green)
 
#draw second coordinate system
xaxis0=arrow(pos=vector(-L/2,0,0)+dr, axis=(L,0,0), shaftwidth=sw, color=color.yellow)
yaxis0=arrow(pos=vector(0,-L/2,0)+dr, axis=(0,L,0), shaftwidth=sw, color=color.yellow)
zaxis0=arrow(pos=vector(0,0,-L/2)+dr, axis=(0,0,L), shaftwidth=sw, color=color.yellow)
 
#draw a particle at position r and draw the position vector r
r=vector(2,0.5,0)
R=0.1
particle=sphere(pos=r, radius=R, color=color.magenta)
rarrow=arrow(pos=(0,0,0), axis=r, shaftwidth=2*sw, color=color.cyan)
 
#calculate the position of the particle in the second coordinate system
r0=r-dr
 
#draw the position vector r0 for second coordinate system
r0arrow=arrow(pos=dr, axis=r0, shaftwidth=2*sw, color=color.blue)


Reference frame moving with a constant velocity

Suppose that the second reference frame is moving with constant velocity $\vec{V}$ and starts with its origin aligned with the first reference frame at $t=0$. Then the origin of the moving frame, relative to the fixed frame, is at the location

$$\Delta \vec{r}= \vec{V}\Delta t$$

and the position of the particle in the fixed frame is

$$\vec{r}=\vec{r}_0 + \vec{V}\Delta t.$$

Moving reference frame in iVisual

Suppose that the moving reference frame has a velocity $\vec{V}=<2,0,0>$ m/s, and the particle is at rest. What is the velocity of the particle relative to the moving reference frame?

Let's write a program to show how the vector $\vec{r}_0$ changes. If we print the vector $\vec{r}_0$ at each clock reading $t$, then we can study the motion of the particle as measured in the reference frame $S_0$.

Note that when executing the cell below, the scene above will begin changing. To slow it down in order to give you time to scroll up, and see the animation, I put a while loop that counted to 5 in 1 second intervals. Thus, it delays 5 second.


In [3]:
#make a list for the 0 coord sys axes
S0coordsys=[xaxis0,yaxis0,zaxis0]

#place moving frame at the origin and update arrows
dr=vector(0,0,0)
#update 0 coord sys
xaxis0.pos=vector(-L/2,0,0)+dr
yaxis0.pos=vector(0,-L/2,0)+dr
zaxis0.pos=vector(0,0,-L/2)+dr
#update arrows
drarrow.axis=dr
r0=r-dr
r0arrow.pos=dr
r0arrow.axis=r0

#define the velocity of the moving frame
V=vector(2,0,0)
t=0
dt=0.01

#fix the size if the window 
scene.range=3
scene.autoscale=0

#delay
N=5 #seconds
n=0
while n<N:
    rate(1)#1 second delay
    n=n+1

#print header
print("r_0 vector (m)", "\t", "t (s)")
print(r0,"\t",t)

#move the S0 coord system and update vectors
while t<1.5:
    rate(20)
    #update S0 coord sys
    for axis in S0coordsys:
        axis.pos=axis.pos+V*dt

    #update vectors
    dr=dr+V*dt
    drarrow.axis=dr
    r0=r-dr
    r0arrow.pos=xaxis0.pos+0.5*xaxis0.axis
    r0arrow.axis=r0
    t=t+dt
    print(r0,t)


r_0 vector (m) 	 t (s)
<2.000000, 0.500000, 0.000000> 	 0
<1.980000, 0.500000, 0.000000> 0.01
<1.960000, 0.500000, 0.000000> 0.02
<1.940000, 0.500000, 0.000000> 0.03
<1.920000, 0.500000, 0.000000> 0.04
<1.900000, 0.500000, 0.000000> 0.05
<1.880000, 0.500000, 0.000000> 0.06
<1.860000, 0.500000, 0.000000> 0.07
<1.840000, 0.500000, 0.000000> 0.08
<1.820000, 0.500000, 0.000000> 0.09
<1.800000, 0.500000, 0.000000> 0.1
<1.780000, 0.500000, 0.000000> 0.11
<1.760000, 0.500000, 0.000000> 0.12
<1.740000, 0.500000, 0.000000> 0.13
<1.720000, 0.500000, 0.000000> 0.14
<1.700000, 0.500000, 0.000000> 0.15
<1.680000, 0.500000, 0.000000> 0.16
<1.660000, 0.500000, 0.000000> 0.17
<1.640000, 0.500000, 0.000000> 0.18
<1.620000, 0.500000, 0.000000> 0.19
<1.600000, 0.500000, 0.000000> 0.2
<1.580000, 0.500000, 0.000000> 0.21
<1.560000, 0.500000, 0.000000> 0.22
<1.540000, 0.500000, 0.000000> 0.23
<1.520000, 0.500000, 0.000000> 0.24
<1.500000, 0.500000, 0.000000> 0.25
<1.480000, 0.500000, 0.000000> 0.26
<1.460000, 0.500000, 0.000000> 0.27
<1.440000, 0.500000, 0.000000> 0.28
<1.420000, 0.500000, 0.000000> 0.29
<1.400000, 0.500000, 0.000000> 0.3
<1.380000, 0.500000, 0.000000> 0.31
<1.360000, 0.500000, 0.000000> 0.32
<1.340000, 0.500000, 0.000000> 0.33
<1.320000, 0.500000, 0.000000> 0.34
<1.300000, 0.500000, 0.000000> 0.35
<1.280000, 0.500000, 0.000000> 0.36
<1.260000, 0.500000, 0.000000> 0.37
<1.240000, 0.500000, 0.000000> 0.38
<1.220000, 0.500000, 0.000000> 0.39
<1.200000, 0.500000, 0.000000> 0.4
<1.180000, 0.500000, 0.000000> 0.41
<1.160000, 0.500000, 0.000000> 0.42
<1.140000, 0.500000, 0.000000> 0.43
<1.120000, 0.500000, 0.000000> 0.44
<1.100000, 0.500000, 0.000000> 0.45
<1.080000, 0.500000, 0.000000> 0.46
<1.060000, 0.500000, 0.000000> 0.47
<1.040000, 0.500000, 0.000000> 0.48
<1.020000, 0.500000, 0.000000> 0.49
<1.000000, 0.500000, 0.000000> 0.5
<0.980000, 0.500000, 0.000000> 0.51
<0.960000, 0.500000, 0.000000> 0.52
<0.940000, 0.500000, 0.000000> 0.53
<0.920000, 0.500000, 0.000000> 0.54
<0.900000, 0.500000, 0.000000> 0.55
<0.880000, 0.500000, 0.000000> 0.56
<0.860000, 0.500000, 0.000000> 0.57
<0.840000, 0.500000, 0.000000> 0.58
<0.820000, 0.500000, 0.000000> 0.59
<0.800000, 0.500000, 0.000000> 0.6
<0.780000, 0.500000, 0.000000> 0.61
<0.760000, 0.500000, 0.000000> 0.62
<0.740000, 0.500000, 0.000000> 0.63
<0.720000, 0.500000, 0.000000> 0.64
<0.700000, 0.500000, 0.000000> 0.65
<0.680000, 0.500000, 0.000000> 0.66
<0.660000, 0.500000, 0.000000> 0.67
<0.640000, 0.500000, 0.000000> 0.68
<0.620000, 0.500000, 0.000000> 0.69
<0.600000, 0.500000, 0.000000> 0.7
<0.580000, 0.500000, 0.000000> 0.71
<0.560000, 0.500000, 0.000000> 0.72
<0.540000, 0.500000, 0.000000> 0.73
<0.520000, 0.500000, 0.000000> 0.74
<0.500000, 0.500000, 0.000000> 0.75
<0.480000, 0.500000, 0.000000> 0.76
<0.460000, 0.500000, 0.000000> 0.77
<0.440000, 0.500000, 0.000000> 0.78
<0.420000, 0.500000, 0.000000> 0.79
<0.400000, 0.500000, 0.000000> 0.8
<0.380000, 0.500000, 0.000000> 0.81
<0.360000, 0.500000, 0.000000> 0.82
<0.340000, 0.500000, 0.000000> 0.83
<0.320000, 0.500000, 0.000000> 0.84
<0.300000, 0.500000, 0.000000> 0.85
<0.280000, 0.500000, 0.000000> 0.86
<0.260000, 0.500000, 0.000000> 0.87
<0.240000, 0.500000, 0.000000> 0.88
<0.220000, 0.500000, 0.000000> 0.89
<0.200000, 0.500000, 0.000000> 0.9
<0.180000, 0.500000, 0.000000> 0.91
<0.160000, 0.500000, 0.000000> 0.92
<0.140000, 0.500000, 0.000000> 0.93
<0.120000, 0.500000, 0.000000> 0.94
<0.100000, 0.500000, 0.000000> 0.95
<0.080000, 0.500000, 0.000000> 0.96
<0.060000, 0.500000, 0.000000> 0.97
<0.040000, 0.500000, 0.000000> 0.98
<0.020000, 0.500000, 0.000000> 0.99
<-0.000000, 0.500000, 0.000000> 1.0
<-0.020000, 0.500000, 0.000000> 1.01
<-0.040000, 0.500000, 0.000000> 1.02
<-0.060000, 0.500000, 0.000000> 1.03
<-0.080000, 0.500000, 0.000000> 1.04
<-0.100000, 0.500000, 0.000000> 1.05
<-0.120000, 0.500000, 0.000000> 1.06
<-0.140000, 0.500000, 0.000000> 1.07
<-0.160000, 0.500000, 0.000000> 1.08
<-0.180000, 0.500000, 0.000000> 1.09
<-0.200000, 0.500000, 0.000000> 1.1
<-0.220000, 0.500000, 0.000000> 1.11
<-0.240000, 0.500000, 0.000000> 1.12
<-0.260000, 0.500000, 0.000000> 1.13
<-0.280000, 0.500000, 0.000000> 1.14
<-0.300000, 0.500000, 0.000000> 1.15
<-0.320000, 0.500000, 0.000000> 1.16
<-0.340000, 0.500000, 0.000000> 1.17
<-0.360000, 0.500000, 0.000000> 1.18
<-0.380000, 0.500000, 0.000000> 1.19
<-0.400000, 0.500000, 0.000000> 1.2
<-0.420000, 0.500000, 0.000000> 1.21
<-0.440000, 0.500000, 0.000000> 1.22
<-0.460000, 0.500000, 0.000000> 1.23
<-0.480000, 0.500000, 0.000000> 1.24
<-0.500000, 0.500000, 0.000000> 1.25
<-0.520000, 0.500000, 0.000000> 1.26
<-0.540000, 0.500000, 0.000000> 1.27
<-0.560000, 0.500000, 0.000000> 1.28
<-0.580000, 0.500000, 0.000000> 1.29
<-0.600000, 0.500000, 0.000000> 1.3
<-0.620000, 0.500000, 0.000000> 1.31
<-0.640000, 0.500000, 0.000000> 1.32
<-0.660000, 0.500000, 0.000000> 1.33
<-0.680000, 0.500000, 0.000000> 1.34
<-0.700000, 0.500000, 0.000000> 1.35
<-0.720000, 0.500000, 0.000000> 1.36
<-0.740000, 0.500000, 0.000000> 1.37
<-0.760000, 0.500000, 0.000000> 1.38
<-0.780000, 0.500000, 0.000000> 1.39
<-0.800000, 0.500000, 0.000000> 1.4
<-0.820000, 0.500000, 0.000000> 1.41
<-0.840000, 0.500000, 0.000000> 1.42
<-0.860000, 0.500000, 0.000000> 1.43
<-0.880000, 0.500000, 0.000000> 1.47
<-0.960000, 0.500000, 0.000000> 1.48
<-0.980000, 0.500000, 0.000000> 1.49
<-1.000000, 0.500000, 0.000000> 1.5

In frame $S$, the particle is at rest. By examining the data, what is the velocity of the particle as measured in frame $S_0$?

Plotting data with matplotlib

It would be nice to graph the data. To do this, we should store the data in lists and use the matplotlib package.


In [8]:
#reset r, r0, and dr; although r didn't change since the particle is at rest it's good practice
r=vector(2,0.5,0)
dr=vector(0,0,0)
r0=r-dr

#reset clock
t=0

#create lists to store data
tlist=[]
xlist=[]

tlist.append(t)
xlist.append(r0.x)

#move the S0 frame and calculate r0
#there's no need to animate, so we won't update arrows
while t<1.5:
    #update vectors
    dr=dr+V*dt
    r0=r-dr
    t=t+dt
    tlist.append(t)
    xlist.append(r0.x)

print(xlist,tlist)


[2, 1.98, 1.96, 1.94, 1.92, 1.9, 1.88, 1.8599999999999999, 1.84, 1.82, 1.8, 1.78, 1.76, 1.74, 1.72, 1.7, 1.68, 1.66, 1.64, 1.6199999999999999, 1.5999999999999999, 1.5799999999999998, 1.5599999999999998, 1.5399999999999998, 1.5199999999999998, 1.5, 1.48, 1.46, 1.44, 1.42, 1.4, 1.38, 1.3599999999999999, 1.3399999999999999, 1.3199999999999998, 1.2999999999999998, 1.2799999999999998, 1.2599999999999998, 1.2399999999999998, 1.2199999999999998, 1.1999999999999997, 1.1799999999999997, 1.1599999999999997, 1.1399999999999997, 1.1199999999999997, 1.0999999999999996, 1.0799999999999996, 1.0599999999999996, 1.0399999999999996, 1.0199999999999996, 0.9999999999999996, 0.9799999999999995, 0.9599999999999995, 0.9399999999999995, 0.9199999999999995, 0.8999999999999995, 0.8799999999999994, 0.8599999999999994, 0.8399999999999994, 0.8199999999999994, 0.7999999999999994, 0.7799999999999994, 0.7599999999999993, 0.7399999999999993, 0.7199999999999993, 0.6999999999999993, 0.6799999999999993, 0.6599999999999993, 0.6399999999999992, 0.6199999999999992, 0.5999999999999992, 0.5799999999999992, 0.5599999999999992, 0.5399999999999991, 0.5199999999999991, 0.4999999999999991, 0.4799999999999991, 0.4599999999999991, 0.43999999999999906, 0.41999999999999904, 0.399999999999999, 0.379999999999999, 0.359999999999999, 0.33999999999999897, 0.31999999999999895, 0.29999999999999893, 0.2799999999999989, 0.2599999999999989, 0.23999999999999888, 0.21999999999999886, 0.19999999999999885, 0.17999999999999883, 0.1599999999999988, 0.1399999999999988, 0.11999999999999877, 0.09999999999999876, 0.07999999999999874, 0.05999999999999872, 0.0399999999999987, 0.019999999999998685, -1.3322676295501878e-15, -0.02000000000000135, -0.04000000000000137, -0.060000000000001386, -0.0800000000000014, -0.10000000000000142, -0.12000000000000144, -0.14000000000000146, -0.16000000000000147, -0.1800000000000015, -0.2000000000000015, -0.22000000000000153, -0.24000000000000155, -0.26000000000000156, -0.2800000000000016, -0.3000000000000016, -0.3200000000000016, -0.34000000000000163, -0.36000000000000165, -0.38000000000000167, -0.4000000000000017, -0.4200000000000017, -0.4400000000000017, -0.46000000000000174, -0.48000000000000176, -0.5000000000000018, -0.5200000000000018, -0.5400000000000018, -0.5600000000000018, -0.5800000000000018, -0.6000000000000019, -0.6200000000000019, -0.6400000000000019, -0.6600000000000019, -0.6800000000000019, -0.700000000000002, -0.720000000000002, -0.740000000000002, -0.760000000000002, -0.780000000000002, -0.800000000000002, -0.8200000000000021, -0.8400000000000021, -0.8600000000000021, -0.8800000000000021, -0.9000000000000021, -0.9200000000000021, -0.9400000000000022, -0.9600000000000022, -0.9800000000000022, -1.0000000000000022] [0, 0.01, 0.02, 0.03, 0.04, 0.05, 0.060000000000000005, 0.07, 0.08, 0.09, 0.09999999999999999, 0.10999999999999999, 0.11999999999999998, 0.12999999999999998, 0.13999999999999999, 0.15, 0.16, 0.17, 0.18000000000000002, 0.19000000000000003, 0.20000000000000004, 0.21000000000000005, 0.22000000000000006, 0.23000000000000007, 0.24000000000000007, 0.25000000000000006, 0.26000000000000006, 0.2700000000000001, 0.2800000000000001, 0.2900000000000001, 0.3000000000000001, 0.3100000000000001, 0.3200000000000001, 0.3300000000000001, 0.34000000000000014, 0.35000000000000014, 0.36000000000000015, 0.37000000000000016, 0.38000000000000017, 0.3900000000000002, 0.4000000000000002, 0.4100000000000002, 0.4200000000000002, 0.4300000000000002, 0.4400000000000002, 0.45000000000000023, 0.46000000000000024, 0.47000000000000025, 0.48000000000000026, 0.49000000000000027, 0.5000000000000002, 0.5100000000000002, 0.5200000000000002, 0.5300000000000002, 0.5400000000000003, 0.5500000000000003, 0.5600000000000003, 0.5700000000000003, 0.5800000000000003, 0.5900000000000003, 0.6000000000000003, 0.6100000000000003, 0.6200000000000003, 0.6300000000000003, 0.6400000000000003, 0.6500000000000004, 0.6600000000000004, 0.6700000000000004, 0.6800000000000004, 0.6900000000000004, 0.7000000000000004, 0.7100000000000004, 0.7200000000000004, 0.7300000000000004, 0.7400000000000004, 0.7500000000000004, 0.7600000000000005, 0.7700000000000005, 0.7800000000000005, 0.7900000000000005, 0.8000000000000005, 0.8100000000000005, 0.8200000000000005, 0.8300000000000005, 0.8400000000000005, 0.8500000000000005, 0.8600000000000005, 0.8700000000000006, 0.8800000000000006, 0.8900000000000006, 0.9000000000000006, 0.9100000000000006, 0.9200000000000006, 0.9300000000000006, 0.9400000000000006, 0.9500000000000006, 0.9600000000000006, 0.9700000000000006, 0.9800000000000006, 0.9900000000000007, 1.0000000000000007, 1.0100000000000007, 1.0200000000000007, 1.0300000000000007, 1.0400000000000007, 1.0500000000000007, 1.0600000000000007, 1.0700000000000007, 1.0800000000000007, 1.0900000000000007, 1.1000000000000008, 1.1100000000000008, 1.1200000000000008, 1.1300000000000008, 1.1400000000000008, 1.1500000000000008, 1.1600000000000008, 1.1700000000000008, 1.1800000000000008, 1.1900000000000008, 1.2000000000000008, 1.2100000000000009, 1.2200000000000009, 1.2300000000000009, 1.2400000000000009, 1.2500000000000009, 1.260000000000001, 1.270000000000001, 1.280000000000001, 1.290000000000001, 1.300000000000001, 1.310000000000001, 1.320000000000001, 1.330000000000001, 1.340000000000001, 1.350000000000001, 1.360000000000001, 1.370000000000001, 1.380000000000001, 1.390000000000001, 1.400000000000001, 1.410000000000001, 1.420000000000001, 1.430000000000001, 1.440000000000001, 1.450000000000001, 1.460000000000001, 1.470000000000001, 1.480000000000001, 1.490000000000001, 1.500000000000001]

Now we need to import matplotlib and graph the data. The "%matplotlib inline" magic command in Notebook causes the graph to be displayed within the page. Without this command, the graph will be displayed in a pop-up window.


In [9]:
%matplotlib inline

In [10]:
import matplotlib.pyplot as plt

In [11]:
plt.title('x vs t')
plt.xlabel('time (s)')
plt.ylabel('x (m)')
plt.plot(tlist, xlist, 'b.')
plt.show()


How would a scientist in the moving frame $S_0$ describe the motion of the particle?


In [ ]: