Wednesday, 28 May 2025

Enneper Surface Pattern using Python

 


import matplotlib.pyplot as plt

import numpy as np

from mpl_toolkits.mplot3d import Axes3D

u=np.linspace(-2,2,100)

v=np.linspace(-2,2,100)

U,V=np.meshgrid(u,v)

X=U-(U**3)/3+U*V**2

Y=V-(V**3)/3+V*U**2

Z=U**2-V**2

fig=plt.figure(figsize=(6,6))

ax=fig.add_subplot(111,projection='3d')

ax.plot_surface(X,Y,Z,cmap='viridis',edgecolor='none',alpha=0.9)

ax.set_title('Enneper Surface')

ax.set_xlabel('X')

ax.set_ylabel('Y')

ax.set_zlabel('Z')

plt.show()

#source code --> clcoding.com 

Code Explanation:

1. Import Libraries

import numpy as np

import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D

NumPy: For numerical operations and creating arrays.

Matplotlib.pyplot: For plotting graphs.

Axes3D: Enables 3D plotting capabilities.

 2. Define Parameter Grid

u = np.linspace(-2, 2, 100)

v = np.linspace(-2, 2, 100)

U, V = np.meshgrid(u, v)

Creates two arrays u and v with 100 points each from -2 to 2.

np.meshgrid creates coordinate matrices U and V for all combinations of u and v. This forms a grid over which the surface is calculated.

 3. Calculate Coordinates Using Parametric Equations

X = U - (U**3)/3 + U*V**2

Y = V - (V**3)/3 + V*U**2

Z = U**2 - V**2

Computes the 3D coordinates of the Enneper surface using its parametric formulas:

 4. Create Figure and 3D Axis

fig = plt.figure(figsize=(10, 8))

ax = fig.add_subplot(111, projection='3d')

Creates a new figure with size 10x8 inches.

 Adds a 3D subplot to the figure for 3D plotting.

 5. Plot the Surface

ax.plot_surface(X, Y, Z, cmap='viridis', edgecolor='none', alpha=0.9)

Plots a 3D surface using the (X, Y, Z) coordinates.

 Uses the 'viridis' colormap for coloring the surface.

 Removes edge lines for a smooth look.

 Sets surface transparency to 90% opacity for better visual depth.

 6. Set Titles and Axis Labels

ax.set_title('Enneper Surface')

ax.set_xlabel('X')

ax.set_ylabel('Y')

ax.set_zlabel('Z')

Adds a title and labels to the X, Y, and Z axes.

 7. Display the Plot

plt.show()

Shows the final 3D plot window displaying the Enneper surface.

 


0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (118) AI (161) Android (25) AngularJS (1) Api (6) Assembly Language (2) aws (27) Azure (8) BI (10) Books (254) Bootcamp (1) C (78) C# (12) C++ (83) Course (84) Coursera (299) Cybersecurity (28) Data Analysis (24) Data Analytics (16) data management (15) Data Science (225) Data Strucures (14) Deep Learning (75) Django (16) Downloads (3) edx (21) Engineering (15) Euron (30) Events (7) Excel (17) Finance (9) flask (3) flutter (1) FPL (17) Generative AI (48) Git (6) Google (47) Hadoop (3) HTML Quiz (1) HTML&CSS (48) IBM (41) IoT (3) IS (25) Java (99) Leet Code (4) Machine Learning (197) Meta (24) MICHIGAN (5) microsoft (9) Nvidia (8) Pandas (12) PHP (20) Projects (32) Python (1219) Python Coding Challenge (898) Python Quiz (348) Python Tips (5) Questions (2) R (72) React (7) Scripting (3) security (4) Selenium Webdriver (4) Software (19) SQL (45) Udemy (17) UX Research (1) web application (11) Web development (7) web scraping (3)

Followers

Python Coding for Kids ( Free Demo for Everyone)