-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy path3D_Triangle_of_ABC_Vizualization.py
53 lines (42 loc) · 1.41 KB
/
3D_Triangle_of_ABC_Vizualization.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
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
import sympy as sp
# Given values
b = 5 # units
c = 10 # units
angle_C_deg = 60 # degrees
# Convert angle from degrees to radians
angle_C_rad = np.radians(angle_C_deg)
# Using the law of sines to find angle B
B = np.arcsin(b * np.sin(angle_C_rad) / c)
angle_B_deg = np.degrees(B)
# Create a DataFrame to store triangle points
data = pd.DataFrame({
'Point': ['A', 'B', 'C'],
'X': [0, c * np.cos(angle_C_rad), c],
'Y': [0, c * np.sin(angle_C_rad), 0]
})
# Create a symbolic representation of angle B
B_symbolic = sp.Symbol('B', real=True)
# Solve for angle B symbolically
eq = sp.Eq(sp.sin(B_symbolic), b * sp.sin(angle_C_rad) / c)
angle_B_rad = sp.solve(eq, B_symbolic)[0]
# Create an interactive triangle plot using Plotly
fig = go.Figure()
# Plot triangle sides
fig.add_trace(go.Scatter(x=data['X'], y=data['Y'], mode='lines+text', text=data['Point'], textposition='top center', line=dict(width=2, color='black')))
# Mark angles
fig.add_trace(go.Scatter(x=[c * 0.2], y=[c * 0.2], mode='text', text=[f'∠B ({angle_B_deg:.2f}°)'], textposition='bottom right', textfont=dict(size=14)))
# Customize the layout
fig.update_layout(
title='Triangle ABC',
xaxis_range=[-1, c + 1],
yaxis_range=[-1, c + 1],
xaxis_title='X-axis',
yaxis_title='Y-axis',
showlegend=False
)
# Show the plot
fig.show()