-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathCreative_3D_ABC_Triangle.py
82 lines (70 loc) · 1.65 KB
/
Creative_3D_ABC_Triangle.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
import numpy as np
import pandas as pd
import plotly.express as px
# Given values
a = 20
c = 25
angle_C_deg = 30
# Convert angle_C_deg to radians
angle_C_rad = np.deg2rad(angle_C_deg)
# Calculate coordinates of triangle vertices
vertices = {
'Point': ['A', 'B', 'C'],
'X': [0, c, c - a * np.cos(angle_C_rad)],
'Y': [0, 0, a * np.sin(angle_C_rad)]
}
# Create a DataFrame for the vertices
df = pd.DataFrame(vertices)
# Create a plotly figure
fig = px.line(df, x='X', y='Y', text='Point')
# Customize the figure
fig.update_traces(marker=dict(size=10),
line=dict(color='black'),
textposition='top center',
textfont=dict(size=14),
name='')
# Add labels for sides and angles
fig.add_annotation(
x=c / 2,
y=a * np.sin(angle_C_rad) / 2,
text=f'A ({angle_A_deg:.2f}°)',
showarrow=False,
font=dict(size=14)
)
fig.add_annotation(
x=c,
y=0,
text=f'C ({angle_C_deg}°)',
showarrow=False,
font=dict(size=14)
)
fig.add_annotation(
x=c - a * np.cos(angle_C_rad) / 2,
y=a * np.sin(angle_C_rad) / 2,
text='b',
showarrow=False,
font=dict(size=14)
)
fig.add_shape(
type='line',
x0=0,
y0=0,
x1=0,
y1=a * np.sin(angle_C_rad),
line=dict(color='red', dash='dash')
)
# Customize layout
fig.update_layout(
xaxis=dict(range=[-5, 30]),
yaxis=dict(range=[-5, 25]),
xaxis_title='X-axis',
yaxis_title='Y-axis',
title='Triangle ABC',
title_font=dict(size=20),
legend=dict(title='Sides and Angles', font=dict(size=14)),
autosize=False,
width=600,
height=500
)
# Show the interactive plot
fig.show()