#!/usr/bin/python3 # ========================================================== # The equation for a cycloid curve is: # x = r(θ - sin(θ)) # y = r(1 - cos(θ)) # # where "r" is the radius of the rolling circle # and "θ" is the angle of rotation. # ========================================================== import math import matplotlib.pyplot as plt # ---------------------------------------------------------- # ---- sin curve x,y coordinates # ---------------------------------------------------------- def sine_curve_xy(): x_coords = [] y_coords = [] for deg in range(0,720,10): x_coords.append(deg) y_coords.append(math.sin(math.radians(deg))) return (x_coords,y_coords) # ---------------------------------------------------------- # ---- sine curve plot # ---------------------------------------------------------- def sine_curve_plot(): # ---- define plot plt.figure(figsize=(8.0,4.0),layout='tight') plt.title('Sine Curve', fontsize=18) plt.xlabel('X', fontsize=14) plt.ylabel('Y', fontsize=14) plt.grid(True) # ---- sine plot coordinates x_coords,y_coords = sine_curve_xy() # ---- plot sine curve plt.plot(x_coords,y_coords,color='red',linewidth=1.0) plt.show() # ---------------------------------------------------------- # ---- cycloid curve x,y coordinates # ---------------------------------------------------------- def cycloid_curve_xy(raidus=10): x_coords = [] y_coords = [] for deg in range(0,720,10): x = raidus * (deg - math.sin(math.radians(deg))) x_coords.append(x) y = raidus * (1 - math.cos(math.radians(deg))) y_coords.append(y) return (x_coords,y_coords) # ---------------------------------------------------------- # ---- cycloid curve plot # ---------------------------------------------------------- def cycloid_curve_plot(): # ---- define plot plt.figure(figsize=(8.0,3.0),layout='tight') plt.title('Cycloid Curve', fontsize=18) plt.xlabel('X', fontsize=14) plt.ylabel('Y', fontsize=14) plt.grid(True) # cycloid plot coordinates x_coords,y_coords = cycloid_curve_xy() # ---- plot cycloid curve plt.plot(x_coords,y_coords,color='red',linewidth=1.0) plt.show() # ---------------------------------------------------------- # ---- main # ---------------------------------------------------------- if __name__ == '__main__': ##sine_curve_plot() cycloid_curve_plot()