-
Notifications
You must be signed in to change notification settings - Fork 114
/
01.Animation_Play_in_3D_Frequency_vs_Tension_and_Wave_Speed.py
111 lines (105 loc) · 3.27 KB
/
01.Animation_Play_in_3D_Frequency_vs_Tension_and_Wave_Speed.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import numpy as np
import pandas as pd
import plotly.graph_objs as go
# Define constants and variables
mu = 0.03 # Linear density in kg/m
length = 2.0 # Length of the string in meters
tension_values = np.linspace(10, 40, 100) # Tension values in N
# Calculate wave speeds and frequencies
wave_speeds = np.sqrt(tension_values / mu)
frequencies = wave_speeds / length
# Create a list to store animation frames
frames = []
# Create animation frames
for i, tension in enumerate(tension_values):
frame = go.Frame(
data=[
go.Scatter3d(
x=tension_values[:i+1],
y=wave_speeds[:i+1],
z=frequencies[:i+1],
mode='markers',
marker=dict(size=5, color='blue')
)
],
name=f'Tension = {tension} N'
)
frames.append(frame)
# Create 3D Visualization using Plotly
fig = go.Figure(
data=[
go.Scatter3d(
x=[tension_values[0]],
y=[wave_speeds[0]],
z=[frequencies[0]],
mode='markers',
marker=dict(size=5, color='blue')
)
],
layout=go.Layout(
scene=dict(
xaxis_title='Tension (N)',
yaxis_title='Wave Speed (m/s)',
zaxis_title='Frequency (Hz)'
),
title='Frequency vs. Tension and Wave Speed',
margin=dict(l=0, r=0, b=0, t=40),
updatemenus=[
{
'buttons': [
{
'args': [None, {'frame': {'duration': 150, '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': 'Tension: ',
'visible': True,
'xanchor': 'right'
},
'transition': {'duration': 300, 'easing': 'cubic-in-out'},
'pad': {'b': 10, 't': 50},
'len': 0.9,
'x': 0.1,
'y': 0,
'steps': [
{
'args': [
[f'Tension = {tension} N'],
{
'frame': {'duration': 300, 'redraw': True},
'mode': 'immediate',
'transition': {'duration': 0}
}
],
'label': f'{tension} N',
'method': 'animate'
}
for tension in tension_values
]
}]
),
frames=frames
)
fig.show()