This project demonstrates how the propagation and interference of waves, as well as their interaction with the environment, can be simulated using mathematical models and computer simulations. The use of random values for the position of wave sources, their frequency, and amplitude, along with the implementation of decreasing amplitude with increasing distance from the source, wave reflection from the edges of the square, and their mutual interference, creates visually interesting patterns that illustrate the complexity of wave interactions in a confined space. The results are visualized using a black-and-white color scale that represents the intensity of the waves at various points within the square space.
Simulation with 1 wave source:
Simulation with 2 wave sources:
Simulation with 3 wave sources:
Simulation with 5 wave sources:
Simulation with 10 wave sources:
Simulation with 50 wave sources:
Simulation with 100 wave sources:
Simulation with 500 wave sources:
Source code
The Python source code for this project is available here:
import numpy as np
import matplotlib.pyplot as plt
import os
import re
# Počet obrázků k vytvoření
num_images = 1
# Nastavení rozsahů pro náhodné hodnoty
frequency_range = (1, 50) # Rozsah frekvencí vln
amplitude_range = (0.1, 1) # Rozsah amplitud vln
# Počet zdrojů
number_of_sources = 3
# Velikost prostoru pro simulaci a rozlišení mřížky
space_size = 5
grid_resolution = 1000
for i in range(num_images):
# Inicializace pole pro simulaci
Z = np.zeros((grid_resolution, grid_resolution))
# Vytvoření mřížky pro simulaci
x = np.linspace(-space_size, space_size, grid_resolution)
y = np.linspace(-space_size, space_size, grid_resolution)
X, Y = np.meshgrid(x, y)
# Generování náhodných zdrojů
for _ in range(number_of_sources):
source_position = np.random.uniform(-space_size, space_size, 2)
frequency = np.random.uniform(*frequency_range)
amplitude = np.random.uniform(*amplitude_range)
# Výpočet vzdálenosti od zdroje a přidání vlny do simulace
R = np.sqrt((X - source_position[0])**2 + (Y - source_position[1])**2)
Z += amplitude * np.sin(frequency * R) / (R + 1) # Přidání útlumu amplitudy
# Odrážení vln od stěn
for wall in [-space_size, space_size]:
R_vertical = np.sqrt((X - 2*wall + source_position[0])**2 + (Y - source_position[1])**2)
R_horizontal = np.sqrt((X - source_position[0])**2 + (Y - 2*wall + source_position[1])**2)
Z += amplitude * np.sin(frequency * R_vertical) / (R_vertical + 1)
Z += amplitude * np.sin(frequency * R_horizontal) / (R_horizontal + 1)
# Vykreslení výsledku
plt.figure(figsize=(10, 10))
plt.imshow(Z, cmap='gray', extent=[-space_size, space_size, -space_size, space_size])
plt.axis('off')
# Před uložením obrázku použijte tight_layout pro optimalizaci rozložení
#plt.tight_layout()
# Uložení obrázku
pattern = r"wave_interference_pattern_(\d+).png"
existing_files = [f for f in os.listdir('.') if re.match(pattern, f)]
if existing_files:
numbers = [int(re.search(pattern, f).group(1)) for f in existing_files]
max_number = max(numbers)
else:
max_number = 0
file_name = f"wave_interference_pattern_{max_number + 1:05d}.png"
plt.savefig(file_name, bbox_inches='tight', pad_inches=0, transparent=False, dpi=(grid_resolution*1.3)//10)
plt.close() # Zavření obrázku po uložení