Circular Wave 3D Mesh Plot in Python

This plot simulates circular waves radiating outward from the origin.

The amplitude decays as the waves spread, creating a visually dynamic $3D$ $mesh$.

1. Import Required Libraries

First, import the necessary libraries:

1
2
import numpy as np
import plotly.graph_objects as go

2. Define the Circular Wave Grid

To create circular waves, we define a grid in polar coordinates (r for radial distance and theta for angle) and convert it to Cartesian coordinates (x and y).

This grid will form a circular, ripple-like structure.

1
2
3
4
5
6
7
8
# Define the polar grid
r = np.linspace(0, 10, 100)
theta = np.linspace(0, 2 * np.pi, 100)
r, theta = np.meshgrid(r, theta)

# Convert to Cartesian coordinates
X = r * np.cos(theta)
Y = r * np.sin(theta)

3. Define the Circular Wave Function for Z Coordinates

Define a wave function that decreases in amplitude as it moves outward.

We can use a sine function with a decaying exponential to achieve this effect:

1
2
# Circular wave function
Z = np.sin(3 * r - theta) * np.exp(-0.3 * r)

4. Reshape Data for the Mesh Plot

Flatten X, Y, and Z to 1D arrays for Plotly’s go.Mesh3d.

1
2
3
X = X.flatten()
Y = Y.flatten()
Z = Z.flatten()

5. Create the Mesh Plot

Now, create the $3D$ $mesh$ plot with customized color and transparency:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Create the mesh plot for the circular wave
fig = go.Figure(
data=[go.Mesh3d(
x=X, y=Y, z=Z,
color='blue',
opacity=0.7,
intensity=Z,
colorscale="Cividis",
alphahull=5
)]
)

# Set layout options for a better view
fig.update_layout(
title="3D Circular Wave Mesh Plot",
scene=dict(
xaxis_title='X-axis',
yaxis_title='Y-axis',
zaxis_title='Z-axis',
camera=dict(
eye=dict(x=1.5, y=1.5, z=1.5)
)
)
)

6. Display the Plot

To display the circular wave plot, use:

1
fig.show()

Explanation of Key Parameters

  • Wave Equation: The function np.sin(3 * r - theta) * np.exp(-0.3 * r) simulates oscillations with amplitude decay, creating a wave pattern that radiates outward.
  • Colorscale: The Cividis scale adds contrast, highlighting the wave peaks and valleys for a dramatic effect.
  • Opacity: Lower opacity adds depth to the plot, making the wave’s radial decay easier to perceive.

This creates a visually engaging $3D$ $mesh$ that mimics ripples in water, showcasing the decaying wave amplitude as it moves outward from the origin.