-
Notifications
You must be signed in to change notification settings - Fork 19
/
3D_Plane_Movement_Animation_with_Angles.py
99 lines (82 loc) · 2.84 KB
/
3D_Plane_Movement_Animation_with_Angles.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
import numpy as np
import pandas as pd
import plotly.graph_objs as go
import plotly.express as px
# Define the initial height 'h' and constants
h = 100 # Replace with the actual height in meters
angle_1_deg = 60
angle_2_deg = 30
# Calculate the horizontal distances 'x' and 'y'
x = h / np.sqrt(3)
y = (2 / np.sqrt(3)) * h
# Calculate the distances traveled at each stage
distance_covered_1 = x
distance_covered_2 = y - x
# Create a DataFrame to store the points for visualization
data = pd.DataFrame({'x': [0, x, x], 'y': [0, 0, y]})
data_labels = ['Initial Position', '60° Elevation', '30° Elevation']
# Create a Plotly scatter plot for the points with annotations
trace = go.Scatter(
x=data['x'],
y=data['y'],
mode='lines+markers+text',
marker=dict(size=10, color='blue'),
text=data_labels,
textposition='top center',
)
# Create a Plotly animation with frames
frames = [go.Frame(data=[go.Scatter(x=data['x'][:i+1], y=data['y'][:i+1],
mode='lines+markers+text',
marker=dict(size=10, color='blue'),
text=data_labels[:i+1],
textposition='top center',
)],
name=f'Frame {i+1}'
) for i in range(len(data))]
layout = go.Layout(
title='Plane Movement Animation',
xaxis=dict(title='Horizontal Distance (m)'),
yaxis=dict(title='Vertical Distance (m)'),
)
fig = go.Figure(data=[trace], layout=layout, frames=frames)
# Add text annotations to display distances
fig.add_annotation(text=f"Distance covered at 60°: {distance_covered_1:.2f} meters",
x=x/2, y=0.2*h, showarrow=False, font=dict(size=14))
fig.add_annotation(text=f"Distance covered at 30°: {distance_covered_2:.2f} meters",
x=(x + y) / 2, y=0.2*h, showarrow=False, font=dict(size=14))
# Add shapes to visualize angles
fig.add_shape(
type='line',
x0=0, y0=0, x1=x, y1=0,
line=dict(color='red', width=2),
xref='x', yref='y'
)
fig.add_shape(
type='line',
x0=x, y0=0, x1=x, y1=h,
line=dict(color='red', width=2),
xref='x', yref='y'
)
fig.add_shape(
type='line',
x0=0, y0=0, x1=y, y1=0,
line=dict(color='green', width=2),
xref='x', yref='y'
)
fig.add_shape(
type='line',
x0=y, y0=0, x1=y, y1=h,
line=dict(color='green', width=2),
xref='x', yref='y'
)
# Add text annotations to display angles
fig.add_annotation(text='60°', x=0.1*x, y=0.1*h, showarrow=False, font=dict(size=14))
fig.add_annotation(text='30°', x=0.1*x + 0.9*y, y=0.1*h, showarrow=False, font=dict(size=14))
# Add title and labels
fig.update_layout(
title_text='Plane Movement Animation with Angles',
xaxis_title='Horizontal Distance (m)',
yaxis_title='Vertical Distance (m)',
)
# Show the animation
fig.show()