Thursday, 24 April 2025

3D Circular Arc Helicoid shape using Python

 


import matplotlib.pyplot as plt

import numpy as np

u=np.linspace(0,4*np.pi,100)

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

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

a=0.5

X=V*np.cos(U)

Y=V*np.sin(U)

Z=a*U

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

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

ax.plot_surface(X,Y,Z,cmap='plasma',alpha=0.8,edgecolor='k')

ax.set_title('3D Circular Arc Pattern')

ax.set_xlabel('X axis')

ax.set_ylabel('Y axis')

ax.set_zlabel('Z axis')

ax.set_box_aspect([1,1,1])

plt.tight_layout()

plt.show()

#source code --> clcoding.com 


Code Explanation:

1. Imports and Setup

import numpy as np

import matplotlib.pyplot as plt

numpy is used for numerical operations and creating coordinate grids.

 matplotlib.pyplot is used to plot the 3D surface.

 2. Creating the Grid

u = np.linspace(0, 4 * np.pi, 100)  # Angular parameter (rotation)

v = np.linspace(-2, 2, 50)          # Radial parameter (radius from center)

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

u spans from 0 to 4ฯ€ — this means the surface will make 2 full twists (since one full twist is 2ฯ€).

 v spans from -2 to 2 — gives the radius of the spiral arms.

 meshgrid(U, V) allows you to create a 2D grid of values to generate a surface.

 3. Parametric Equations of a Helicoid

a = 0.5  # Twist rate or height per unit angle

X = V * np.cos(U)

Y = V * np.sin(U)

Z = a * U

These are the parametric equations for a helicoid:

 X and Y describe a circle at every vertical level.

 Z increases with U, making it spiral upwards — that's the helical twist.

 The value a = 0.5 controls the pitch or height per rotation.

 4. Plotting the Surface

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

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

Creates a 3D figure and axis.

ax.plot_surface(X, Y, Z, cmap='plasma', alpha=0.8, edgecolor='k')

plot_surface() draws the helicoid.

 cmap='plasma' gives it a vivid color gradient.

 alpha=0.8 adds a little transparency.

 edgecolor='k' adds a thin black edge for clarity.

 5. Titles and Labels

ax.set_title('3D Circular Arc (Helicoid Surface)')

ax.set_xlabel('X axis')

ax.set_ylabel('Y axis')

ax.set_zlabel('Z axis')

Labels the axes and gives the chart a title.

 6. Aspect Ratio and Display

ax.set_box_aspect([1,1,1])  # Ensures all axes are equally scaled

plt.tight_layout()

plt.show()

Ensures the plot isn't distorted and then renders it on screen.

 


0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (118) AI (152) Android (25) AngularJS (1) Api (6) Assembly Language (2) aws (27) Azure (8) BI (10) Books (251) Bootcamp (1) C (78) C# (12) C++ (83) Course (84) Coursera (298) Cybersecurity (28) Data Analysis (24) Data Analytics (16) data management (15) Data Science (217) Data Strucures (13) Deep Learning (68) Django (16) Downloads (3) edx (21) Engineering (15) Euron (30) Events (7) Excel (17) Finance (9) flask (3) flutter (1) FPL (17) Generative AI (47) 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 (186) Meta (24) MICHIGAN (5) microsoft (9) Nvidia (8) Pandas (11) PHP (20) Projects (32) Python (1218) Python Coding Challenge (884) Python Quiz (342) 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)