Real-World Applications
Graphics and Game Development
Trigonometric functions are crucial in creating dynamic visual effects:
import math
import numpy as np
import matplotlib.pyplot as plt
def circular_motion(radius, angle):
x = radius * math.cos(angle)
y = radius * math.sin(angle)
return x, y
## Simulate circular motion
angles = np.linspace(0, 2*math.pi, 100)
x_coords = [circular_motion(1, angle)[0] for angle in angles]
y_coords = [circular_motion(1, angle)[1] for angle in angles]
plt.plot(x_coords, y_coords)
plt.title('Circular Motion Simulation')
plt.axis('equal')
plt.show()
Signal Processing
Trigonometric functions model wave patterns:
import numpy as np
import matplotlib.pyplot as plt
def generate_wave(frequency, amplitude, phase):
time = np.linspace(0, 1, 500)
wave = amplitude * np.sin(2 * np.pi * frequency * time + phase)
return time, wave
## Generate and plot different waves
time1, wave1 = generate_wave(5, 1, 0)
time2, wave2 = generate_wave(10, 0.5, np.pi/2)
plt.figure(figsize=(10, 4))
plt.subplot(2, 1, 1)
plt.plot(time1, wave1)
plt.title('Low Frequency Wave')
plt.subplot(2, 1, 2)
plt.plot(time2, wave2)
plt.title('High Frequency Wave')
plt.tight_layout()
plt.show()
Navigation and Geospatial Calculations
import math
def haversine_distance(lat1, lon1, lat2, lon2):
R = 6371 ## Earth's radius in kilometers
## Convert latitude and longitude to radians
lat1, lon1, lat2, lon2 = map(math.radians, [lat1, lon1, lat2, lon2])
## Haversine formula
dlat = lat2 - lat1
dlon = lon2 - lon1
a = math.sin(dlat/2)**2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon/2)**2
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a))
return R * c
## Calculate distance between two coordinates
distance = haversine_distance(40.7128, -74.0060, 51.5074, -0.1278)
print(f"Distance between New York and London: {distance:.2f} km")
Application Areas
Domain |
Trigonometric Use |
Example |
Physics |
Wave Modeling |
Sound, Light Waves |
Engineering |
Structural Analysis |
Bridge Design |
Robotics |
Motion Planning |
Robotic Arm Movements |
Computer Vision |
Image Transformations |
Rotation, Scaling |
Machine Learning and Data Science
import numpy as np
def feature_engineering_with_trig():
## Generate synthetic data
x = np.linspace(0, 10, 100)
## Create features using trigonometric transformations
sin_feature = np.sin(x)
cos_feature = np.cos(x)
return sin_feature, cos_feature
## Demonstrate feature generation
sin_data, cos_data = feature_engineering_with_trig()
Visualization of Trigonometric Applications
graph TD
A[Trigonometric Functions] --> B[Graphics]
A --> C[Signal Processing]
A --> D[Navigation]
A --> E[Machine Learning]
A --> F[Robotics]
Key Takeaways
- Trigonometric functions are versatile computational tools
- Applications span multiple scientific and engineering domains
- Python provides robust libraries for trigonometric calculations
- Understanding these functions enables complex problem-solving
LabEx learners can leverage these techniques to solve real-world computational challenges efficiently.