Thursday, 10 April 2025

3D Origami Pattern using Python

 


import matplotlib.pyplot as plt

import numpy as np

x=np.linspace(0,10,100)

y=np.linspace(0,10,100)

X,Y=np.meshgrid(x,y)

Z=np.sin(X)*np.cos(Y)

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

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

ax.plot_surface(X,Y,Z,cmap='plasma',edgecolor='k',linewidth=0.3)

ax.set_title("3D Folded Origami Pattern ")

plt.show()

#source code --> clcoding.com

Code Explanation:

1. Importing Libraries

import numpy as np

import matplotlib.pyplot as plt

numpy (as np): Used for numerical operations and array handling.

 matplotlib.pyplot (as plt): Used for plotting and displaying graphs.

 2. Creating the Grid

x = np.linspace(0, 10, 100)

y = np.linspace(0, 10, 100)

X, Y = np.meshgrid(x, y)

np.linspace(0, 10, 100): Creates 100 values linearly spaced from 0 to 10 for both x and y axes.

 np.meshgrid(x, y): Converts the 1D x and y arrays into 2D coordinate grids (X, Y).

 This is needed to plot a surface where each (x, y) pair will have a height Z.

 3. Defining the Height (Z-values)

Z = np.sin(X) * np.cos(Y)

This creates a wave-like height map:

 sin(X) gives you waves along the x-direction.

 cos(Y) gives waves in the y-direction.

 Multiplying them results in a folded checkerboard-like wave pattern — similar to a Miura fold in origami, where some parts are folded up and others down.

 It visually mimics the alternating mountain-valley folds.

 4. Creating the Plot

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

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

Creates a figure (fig) with a specific size (10 by 6 inches).

 Adds a 3D subplot (ax) to the figure using projection='3d'.

 5. Plotting the 3D Surface

ax.plot_surface(X, Y, Z, cmap='plasma', edgecolor='k', linewidth=0.3)

plot_surface: Draws a 3D surface plot.

 X, Y, Z: Coordinates of the surface.

 cmap='plasma': Applies a colorful colormap for aesthetics (from yellow to purple).

 edgecolor='k': Edges of the grid are black, which enhances the “folded paper” look.

 linewidth=0.3: Makes the grid edges thin for sharp creases, like origami folds.

 6. Final Touches

ax.set_title("3D Folded Origami Pattern (Miura-inspired)")

plt.show()

Adds a title to the plot.

 plt.show() renders and displays the 3D plot window.


Related Posts:

0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (111) AI (41) Android (24) AngularJS (1) Api (2) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (200) C (77) C# (12) C++ (83) Course (67) Coursera (253) Cybersecurity (25) Data Analysis (3) Data Analytics (4) data management (11) Data Science (149) Data Strucures (8) Deep Learning (21) Django (16) Downloads (3) edx (2) Engineering (14) Euron (29) Events (6) Excel (13) Factorial (1) Finance (6) flask (3) flutter (1) FPL (17) Generative AI (11) Google (38) Hadoop (3) HTML Quiz (1) HTML&CSS (47) IBM (30) IoT (1) IS (25) Java (93) Java quiz (1) Leet Code (4) Machine Learning (86) Meta (22) MICHIGAN (5) microsoft (4) Nvidia (4) Pandas (4) PHP (20) Projects (29) pyth (1) Python (1067) Python Coding Challenge (465) Python Quiz (138) Python Tips (5) Questions (2) R (70) React (6) Scripting (3) security (3) Selenium Webdriver (4) Software (17) SQL (42) UX Research (1) web application (8) Web development (4) web scraping (2)

Followers

Python Coding for Kids ( Free Demo for Everyone)