-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy path3D_Surface_Plot_of_Sine_and_Cosine.py
65 lines (58 loc) · 2 KB
/
3D_Surface_Plot_of_Sine_and_Cosine.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
# Step 1: Setting Up the Environment
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import plotly.express as px
import sympy as sp
import torch
import sklearn
import scipy
# Step 2: Data Preparation
# Create a dataset of angles (θ)
angles_degrees = np.arange(0, 360, 1)
angles_radians = np.radians(angles_degrees)
# Calculate trigonometric ratios
sine_values = np.sin(angles_radians)
cosine_values = np.cos(angles_radians)
tangent_values = np.tan(angles_radians)
cosecant_values = 1 / sine_values
secant_values = 1 / cosine_values
cotangent_values = 1 / tangent_values
# Create a DataFrame to store the data
trig_df = pd.DataFrame({
'Angle (degrees)': angles_degrees,
'Angle (radians)': angles_radians,
'Sine': sine_values,
'Cosine': cosine_values,
'Tangent': tangent_values,
'Cosecant': cosecant_values,
'Secant': secant_values,
'Cotangent': cotangent_values
})
# Step 3: Data Visualization
# Create 3D surface plots using Matplotlib
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_trisurf(angles_degrees, sine_values, cosine_values, cmap='viridis')
ax.set_xlabel('Angle (degrees)')
ax.set_ylabel('Sine')
ax.set_zlabel('Cosine')
plt.title('3D Surface Plot of Sine and Cosine')
plt.show()
# Step 4: Equations and Formulas
# Use LaTeX formatting with Matplotlib to display equations
plt.text(30, 0.5, r'$\sin(\theta) = \frac{Opposite}{Hypotenuse}$', fontsize=12)
plt.text(30, 0.4, r'$\cos(\theta) = \frac{Adjacent}{Hypotenuse}$', fontsize=12)
# Add more equations as needed
# Step 5: Mathematical Dance (animations, interactive elements)
# Create an animation of a sine wave using Matplotlib
def update(num, data, line):
line.set_data(data[..., :num])
return line,
data = np.array([angles_degrees, sine_values])
fig, ax = plt.subplots()
line, = ax.plot([], [], lw=2)
ani = animation.FuncAnimation(fig, update, frames=len(angles_degrees), fargs=(data, line), blit=True)
plt.title('Sine Wave Animation')
plt.show()