-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy path2D_Trigonometry_triangles_Hypotenuse_Adjacent_and_Opposite.py
64 lines (50 loc) · 1.69 KB
/
2D_Trigonometry_triangles_Hypotenuse_Adjacent_and_Opposite.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
import sympy as sp
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# Define symbols for angles and sides
A, B, C = sp.symbols('A B C')
AB, BC, AC = sp.symbols('AB BC AC')
# Pythagorean theorem
pythagorean_theorem = sp.Eq(AB**2 + BC**2, AC**2)
# Express equations and formulas
equation1 = sp.Eq(AB, sp.sqrt(AC**2 - BC**2))
equation2 = sp.Eq(BC, sp.sqrt(AC**2 - AB**2))
# Create a DataFrame to store triangle data
data = {'Angle_A': [], 'Angle_B': [], 'Side_C': [], 'Side_AB': [], 'Side_BC': []}
# Generate random right-angle triangles and calculate missing sides
np.random.seed(42)
for _ in range(10):
angle_A = np.random.randint(30, 61)
angle_B = 90 - angle_A
side_C = np.random.randint(5, 15)
# Calculate missing sides using equations
side_AB = sp.sqrt(side_C**2 - BC**2).evalf(subs={BC: side_C, AC: side_C})
side_BC = sp.sqrt(side_C**2 - AB**2).evalf(subs={AB: side_C, AC: side_C})
data['Angle_A'].append(angle_A)
data['Angle_B'].append(angle_B)
data['Side_C'].append(side_C)
data['Side_AB'].append(side_AB)
data['Side_BC'].append(side_BC)
df = pd.DataFrame(data)
# 3D Visualization using Matplotlib
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
for i, row in df.iterrows():
x = [0, 0, 0]
y = [0, row['Side_BC'], 0]
z = [0, 0, 0]
ax.plot(x, y, z, color='b')
x = [0, 0, row['Side_AB']]
y = [0, 0, 0]
z = [0, row['Side_BC'], 0]
ax.plot(x, y, z, color='b')
x = [0, 0, row['Side_AB']]
y = [0, row['Side_BC'], row['Side_C']]
z = [0, 0, 0]
ax.plot(x, y, z, color='b')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.show()