2 patterns-animation-Sine-Wave-Interference
Balazs Horvath edited this page 2026-04-18 11:13:07 +02:00

Sine Wave Interference

Torch-based wave interference pattern demonstrating constructive and destructive interference.

Mathematical Formula


I = \sin(k_1 x + \omega_1 t) + \sin(k_2 y + \omega_2 t) + \sin(k_3(x+y)/2 + \omega_3 t)

Where:

  • k_1, k_2, k_3 are spatial frequencies
  • \omega_1, \omega_2, \omega_3 are temporal frequencies
  • Addition creates constructive/destructive interference sine waves with different orientations
  • Interference creates complex patterns
  • Trigonometric color mapping

How It Works

Wave interference demonstrates how waves interact. When waves overlap, they can reinforce (constructive interference) or cancel (destructive interference), creating complex geometric patterns.

Implementation

import torch

width, height = 512, 512
frames = []

for t in range(30):
    x = torch.linspace(0, 4*torch.pi, width)
    y = torch.linspace(0, 4*torch.pi, height)
    X, Y = torch.meshgrid(x, y, indexing='ij')
    
    # Multiple sine waves with different frequencies
    wave1 = torch.sin(X + t/5)
    wave2 = torch.sin(Y + t/5)
    wave3 = torch.sin((X + Y)/2 + t/5)
    
    # Interference pattern
    interference = wave1 + wave2 + wave3
    interference = (interference + 3) / 6  # Normalize
    
    # Convert to RGB
    rgb = torch.stack([
        interference,
        torch.sin(interference * torch.pi),
        torch.cos(interference * torch.pi)
    ], dim=-1)
    rgb = (rgb + 1) / 2  # Normalize to 0-1
    frames.append(rgb)

output_image = torch.stack(frames, dim=0)  # Shape: [30, H, W, 3]

Line-by-Line Explanation

interference = wave1 + wave2 + wave3

Additive superposition of three waves.

interference = (interference + 3) / 6

Normalizes from [-3, 3] to [0, 1].

rgb = torch.stack([interference, torch.sin(interference * torch.pi), torch.cos(interference * torch.pi)], dim=-1)

Maps interference to RGB using sine and cosine for color variation.

Customization

More Waves

wave4 = torch.sin((X - Y)/2 + t/5)
interference = wave1 + wave2 + wave3 + wave4

Different Frequencies

wave1 = torch.sin(2*X + t/5)  # Tighter

Multiplicative Interference

interference = wave1 * wave2 * wave3  # Moiré effect

References