Processing math: 100%
≡ Menu

Visualizing the Möbius Strip in Python…

The formulation of the Möbius strip involves a parameterization in terms of two variables: \theta, which is an angle that varies from 0 to 2 \pi, and w, which is a distance from the centerline of the strip and varies between -1 and 1.

Given these parameters, the (x, y, z) coordinates for points on the Möbius strip can be determined using the following equations:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import numpy as np
import matplotlib.pyplot as plt
 
# Create a Möbius strip
theta = np.linspace(0, 2 * np.pi, 100)
w = np.linspace(-1, 1, 20)
theta, w = np.meshgrid(theta, w)
phi = 0.5 * theta
r = 1 + w * np.cos(phi)
x = np.cos(theta) * r
y = np.sin(theta) * r
z = w * np.sin(phi)
 
# Plot the Möbius strip
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z, edgecolor='k', color='c')
ax.view_init(50, 30# Adjust view angle for better visualization
ax.set_title('Möbius Strip in 3D')
plt.show()

Visualization Strategy:

  1. Parameter Space Definition: We begin by defining our parameter space for θ and w. The variable θ spans the entire 360-degree range of the strip, while w varies between -1 and 1 to account for the width of the strip.
  2. Meshgrid Creation: Using NumPy’s meshgrid function, we create a grid of points in the (θ, w) parameter space. Each combination of (θ, w) corresponds to a unique point on the Möbius strip.
  3. Position Calculation: For every combination of (θ, w), we compute the x, y, and z coordinates using the above equations.
  4. 3D Plotting: Using Matplotlib’s 3D plotting capabilities, we then plot the computed (x, y, z) coordinates as a surface. The edgecolor is set to ‘k’ (black) to distinguish between individual segments on the strip, and color is set to ‘c’ (cyan) for the surface color.
  5. View Angle Adjustment: The line ax.view_init(50, 30) adjusts the view angle of the 3D plot, making it easier to perceive the Möbius strip’s twist.
{ 0 comments… add one }

Rispondi