Friday, 28 March 2025

Cycloid and Epicycloid Pattern using Python

 


import numpy as np

import matplotlib.pyplot as plt

r = 1

theta = np.linspace(0, 4 * np.pi, 1000)

x_cycloid = r * (theta - np.sin(theta))

y_cycloid = r * (1 - np.cos(theta))

R = 3

r_epicycloid = 1

x_epicycloid = (R + r_epicycloid) * np.cos(theta) - r_epicycloid * np.cos((R + r_epicycloid) / r_epicycloid * theta)

y_epicycloid = (R + r_epicycloid) * np.sin(theta) - r_epicycloid * np.sin((R + r_epicycloid) / r_epicycloid * theta)

plt.figure(figsize=(10, 5))

plt.subplot(1, 2, 1)

plt.plot(x_cycloid, y_cycloid, color='blue')

plt.title('Cycloid')

plt.axis('equal')

plt.subplot(1, 2, 2)

plt.plot(x_epicycloid, y_epicycloid, color='red')

plt.title('Epicycloid')

plt.axis('equal')

plt.tight_layout()

plt.show()

#source code --> clcoding.com 

Code Explanation:

1. Importing Libraries
import numpy as np
import matplotlib.pyplot as plt
NumPy: Used for creating numerical arrays and performing mathematical operations.
Matplotlib: Used for plotting the Cycloid and Epicycloid curves.

2. Define Parameters for the Cycloid
r = 1
theta = np.linspace(0, 4 * np.pi, 1000)
r = 1: Radius of the generating circle.
theta: Array of 1000 values equally spaced from 0 to 4π, representing the angle in radians.
This ensures a smooth plot for one complete oscillation.

3. Calculate the Cycloid Coordinates
x_cycloid = r * (theta - np.sin(theta))
y_cycloid = r * (1 - np.cos(theta))
Cycloid Equation:
x=r(t−sin(t)),y=r(1−cos(t))
Explanation:
x represents the horizontal motion of a point on the wheel as it rolls.
y represents the vertical motion of the point.

This forms a Cycloid — the path traced by a point on a rolling circle.

4. Define Parameters for the Epicycloid
R = 3
r_epicycloid = 1
R = 3: Radius of the stationary larger circle.
r_epicycloid = 1: Radius of the smaller rotating circle that rolls on the outside.

5. Calculate the Epicycloid Coordinates
x_epicycloid = (R + r_epicycloid) * np.cos(theta) - r_epicycloid * np.cos((R + r_epicycloid) / r_epicycloid * theta)
y_epicycloid = (R + r_epicycloid) * np.sin(theta) - r_epicycloid * np.sin((R + r_epicycloid) / r_epicycloid * theta)

Epicycloid Equation:
Explanation:
R is the radius of the fixed circle.
r is the radius of the rolling circle.
The trace of a point on the smaller circle as it rolls on the outer edge of the larger circle forms an Epicycloid.

6. Plot the Cycloid and Epicycloid
plt.figure(figsize=(10, 5))
Creates a figure of size 10x5 for side-by-side comparison.

7. Plot Cycloid
plt.subplot(1, 2, 1)
plt.plot(x_cycloid, y_cycloid, color='blue')
plt.title('Cycloid')
plt.axis('equal')
plt.subplot(1, 2, 1) creates the left plot (Cycloid).

plt.plot() plots the blue Cycloid.

plt.axis('equal') ensures the aspect ratio is equal, so the curve is accurately represented.

8. Plot Epicycloid
plt.subplot(1, 2, 2)
plt.plot(x_epicycloid, y_epicycloid, color='red')
plt.title('Epicycloid')
plt.axis('equal')
plt.subplot(1, 2, 2) creates the right plot (Epicycloid).

plt.plot() plots the red Epicycloid.

9. Final Touch and Display
plt.tight_layout()
plt.show()
plt.tight_layout() adjusts subplot spacing to prevent overlapping.
plt.show() renders the plot on the screen.


0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (96) AI (39) Android (24) AngularJS (1) Api (2) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (197) C (77) C# (12) C++ (83) Course (67) Coursera (249) Cybersecurity (25) Data Analysis (2) Data Analytics (2) data management (11) Data Science (148) 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 (36) Hadoop (3) HTML Quiz (1) HTML&CSS (47) IBM (30) IoT (1) IS (25) Java (93) Java quiz (1) Leet Code (4) Machine Learning (85) Meta (22) MICHIGAN (5) microsoft (4) Nvidia (4) Pandas (4) PHP (20) Projects (29) pyth (1) Python (1042) Python Coding Challenge (456) Python Quiz (117) Python Tips (5) Questions (2) R (70) React (6) Scripting (1) 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)