In: Computer Science
The shape of a limacon can be defined parametrically as
r = r0 + cos θ,
x = r cos θ,
y = r sin θ.
When r0 = 1, this curve is called a cardioid. Use this definition to plot the shape of a limacon for r0 = 0.8, r0 = 1.0, and r0 = 1.2. Be sure to use enough points that the curve is closed and appears smooth (except for the cusp in the cardioid). Use a legend to identify which curve is which. This is python programming
import matplotlib.pyplot as plt
import math
from matplotlib.pyplot import figure
#Set figure size
figure(num=None, figsize=(5,10))
r_values = [0.8, 1.0, 1.2]
#We will create subplots in 3x1 arrangement
for j in range(1,4):
ax = plt.subplot(3,1, j)
#3,1,j means 3rd row, 1st column, jth subplot
#Set title for jth subplot
ax.set_title(str(r_values[j-1]))
x = []
#Empty lists that will store values of x and y
y = []
#Generating x and y values according to r and
theta as given in equation
for theta in range(0,360):
r = r_values[j-1] +
math.cos(theta)
x.append(r*math.cos(theta))
y.append(r*math.sin(theta))
#Plot x,y points
plt.scatter(x, y,
color='r')