-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathLength_of_side_a_and_b.py
More file actions
54 lines (42 loc) · 1.24 KB
/
Length_of_side_a_and_b.py
File metadata and controls
54 lines (42 loc) · 1.24 KB
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
import numpy as np
import matplotlib.pyplot as plt
from sympy import symbols, Eq, solve
import math
# Given data
hypotenuse = 10 # cm
angle_deg = 30 # degrees
# Calculate the length of the side opposite the 30-degree angle (a)
angle_rad = math.radians(angle_deg)
a = hypotenuse * math.sin(angle_rad)
# Calculate the length of the side adjacent to the 30-degree angle (b)
b = hypotenuse * math.cos(angle_rad)
# Create a 3D visualization of the triangle
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# Define the vertices of the triangle
vertices = np.array([[0, 0, 0], [a, 0, 0], [0, b, 0]])
# Define the edges of the triangle
edges = [
[vertices[0], vertices[1]],
[vertices[0], vertices[2]],
[vertices[1], vertices[2]]
]
# Plot the vertices
ax.scatter(vertices[:, 0], vertices[:, 1], vertices[:, 2], c='r', marker='o')
# Plot the edges
for edge in edges:
xs, ys, zs = zip(*edge)
ax.plot(xs, ys, zs)
# Set labels for the axes
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
# Set limits for the axes
ax.set_xlim([0, 12])
ax.set_ylim([0, 12])
ax.set_zlim([0, 12])
# Show the 3D plot
plt.show()
# Print the calculated side lengths
print(f"Length of side 'a': {a:.2f} cm")
print(f"Length of side 'b': {b:.2f} cm")