-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy path01.Animating_3D_Kinetic_Energy_Evolution.py
75 lines (67 loc) · 2.27 KB
/
01.Animating_3D_Kinetic_Energy_Evolution.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import numpy as np
import plotly.graph_objects as go
import sympy as sp
# Define symbols for symbolic calculations
x, t, A, omega, mu, v = sp.symbols('x t A omega mu v')
# Define given parameters
omega = sp.symbols('omega')
mu = sp.symbols('mu')
v = sp.symbols('v')
# Define the kinetic energy equation
kinetic_energy = 0.5 * mu * A**2 * omega**2 * v**2 * sp.cos(2 * sp.pi * v * t - 2 * sp.pi * v * x)
# Create a meshgrid for x, t
x_values = np.linspace(0, 1, 100)
t_values = np.linspace(0, 1, 50)
X, T = np.meshgrid(x_values, t_values)
# Evaluate kinetic energy for the meshgrid
kinetic_energy_mesh = np.array([[float(kinetic_energy.subs([(A, 1), (omega, 1), (mu, 1), (v, 1), (t, t_val), (x, x_val)])) for x_val in x_values] for t_val in t_values])
# Create an animated surface plot using Plotly
frames = [go.Frame(data=[go.Surface(z=kinetic_energy_mesh[:i+1, :], x=X, y=T[:i+1, :])]) for i in range(len(t_values))]
fig = go.Figure(data=[go.Surface(z=kinetic_energy_mesh, x=X, y=T)], frames=frames)
fig.update_layout(
title='Animating Kinetic Energy Evolution',
scene=dict(
xaxis_title='Position (x)',
yaxis_title='Time (t)',
zaxis_title='Kinetic Energy',
),
updatemenus=[{
'buttons': [
{
'args': [None, {'frame': {'duration': 50, 'redraw': True}, 'fromcurrent': True}],
'label': 'Play',
'method': 'animate',
},
{
'args': [[None], {'frame': {'duration': 0, 'redraw': True}, 'mode': 'immediate', 'transition': {'duration': 0}}],
'label': 'Pause',
'method': 'animate',
},
],
'direction': 'left',
'pad': {'r': 10, 't': 87},
'showactive': False,
'type': 'buttons',
'x': 0.1,
'xanchor': 'right',
'y': 0,
'yanchor': 'top',
}],
sliders=[{
'active': 0,
'yanchor': 'top',
'xanchor': 'left',
'currentvalue': {
'font': {'size': 20},
'prefix': 'Time:',
'visible': True,
'xanchor': 'right',
},
'transition': {'duration': 300, 'easing': 'cubic-in-out'},
'pad': {'b': 10, 't': 50},
'len': 0.9,
'x': 0.1,
'y': 0,
}],
)
fig.show()