Parallel Frames#
Let \(\mathbf{e}\) and \(\mathbf{e}'\) represent two inertial observers. \(\mathbf{e}'\) moving parallel to \(\mathbf{e}\) at a constant velocity \(v=[v_1\:\:\:v_2\:\:\:v_3]^T\).
We’ll animate those frames.
Import following libraries on your notebook
[3]:
import plotly.graph_objects as go
import numpy as np
Note
The functions create_line_trace
, create_point_trace
, create_arrow_trace
, and and
others were written in previous tutorials. Please include them in your notebook on top before
starting to follow this tutorial. You can download it by clicking the Download icon on the
Navigation Bar.
Since we have explained the syntax and functions going to use here I am leaving the code only. Follow the previous tutorials for better understanding. Hit the play button and see!
[5]:
traces = []
frames = []
origin = [0, 0, 0]
origin_prime = [5, 5, 5]
interval = np.linspace(0, 50, 100)
# Add origin 'O'
traces.append(create_point_trace(origin_prime, color='black', size=3, name="O'"))
# Add origin 'O'
traces.append(create_point_trace(origin, color='black', size=3, name='O'))
# Create orthonormal frame traces
frame_traces = create_orthonormal_frame_traces(frame_name="e'", origin=origin_prime, length=10, color='green')
traces.extend(frame_traces)
# Create orthonormal frame traces
frame_traces = create_orthonormal_frame_traces(frame_name='e', origin=origin, length=10, color='red')
traces.extend(frame_traces)
traces.append(create_line_trace(start=origin, end=[50, 0, 0], color='blue', width=3, dash='dash', name='e', showlegend=True))
traces.append(create_line_trace(start=[0, 5, 5], end=[50, 5, 5], color='purple', width=3, dash='dash', name="e'", showlegend=True))
velocity_prime = 0.5 # Velocity for frame 'e''
velocity = 1 # Velocity for frame 'e'
# Animation
for i in range(0, len(interval), 5):
new_origin_prime = [origin_prime[0] + interval[i] * velocity_prime, origin_prime[1], origin_prime[2]]
new_origin = [origin[0] + interval[i] * velocity, origin[1], origin[2]]
frame_data = [
# Move origin prime 'O''
create_point_trace(new_origin_prime, color='black', size=3, name="O'"),
# Move origin 'O'
create_point_trace(new_origin, color='black', size=3, name='O'),
]
# Move the orthonormal frames
frame_traces_prime = create_orthonormal_frame_traces(frame_name="e'", origin=new_origin_prime, length=10, color='green')
frame_traces = create_orthonormal_frame_traces(frame_name='e', origin=new_origin, length=10, color='red')
frame_data.extend(frame_traces_prime)
frame_data.extend(frame_traces)
frames.append(go.Frame(data=frame_data))
# Set layout for the figure
layout = create_3d_layout(title='Parallel Frames', xaxis_title='e1 Axis', yaxis_title='e2 Axis', zaxis_title='e3 Axis')
fig = go.Figure()
fig = go.Figure(data=traces, layout=layout, frames=frames)
axis_range = [0, 60]
# Adjust the camera settings
fig.update_layout(
scene=dict(
xaxis=dict(range=axis_range),
yaxis=dict(range=axis_range),
zaxis=dict(range=axis_range),
camera=dict(
up=dict(x=0, y=0, z=1), # Sets the up direction (in this case, the z-axis is up)
center=dict(x=0, y=0, z=0), # Centers the view on the given coordinates
eye=dict(x=1, y=-1.25, z=1.25) # Sets the position of the camera
),
aspectmode='cube' # Keeps the aspect ratio of the axes fixed
)
)
# Add play and pause buttons
fig.update_layout(
updatemenus=[
dict(
type="buttons",
buttons=[
dict(label="Play",
method="animate",
args=[None, dict(frame=dict(duration=50, redraw=True), fromcurrent=True)]),
dict(label="Pause",
method="animate",
args=[[None], dict(frame=dict(duration=0, redraw=False), mode="immediate")])
]
)
]
)
fig.show()