How to plot a corrugated circle in cartesian?

拜拜、爱过 提交于 2021-01-28 09:00:52

问题


I'm looking for a way to plot a corrugated circle in Python. My attempt doesn't produce the correct output:

from matplotlib import pyplot as plt
import numpy as np
from math import pi

x=np.linspace(-10,10,100)
y=x

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

circle = (X-np.cos(2*pi*0.2*Y))**2 + (Y-np.sin(2*pi*0.2*X))**2 - 5.

plt.contour(X,Y,circle,[0])
plt.show()

theta = np.linspace(-pi,pi,100)
courbure = np.sin(theta*10)

plt.plot(theta,courbure)
plt.show()
    
circle2 = (X-(courbure*np.cos(theta)))**2 + (Y-np.sin(theta)*courbure)**2 - courbure**2
plt.contour(X,Y,circle2)
plt.show()

Thank you.


回答1:


I have plot a corrugate circle using a sinusoidal wave of a frequency egal to 10. The radius oscillate between 0.9 et 1. because i take the negative absolute part of the sinus. The amplitude is divided by 10.

For increase the corrugation you have to increase the frequency. Here f=10.

from matplotlib import pyplot as plt
import numpy as np
from math import pi

x=np.linspace(-10,10,1000)
y=x

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

circle = (X)**2 + (Y)**2 - (1+ -np.abs(np.sin(np.arctan(Y/X)*10))/10)

plt.contour(X,Y,circle)
plt.show()


来源:https://stackoverflow.com/questions/62879754/how-to-plot-a-corrugated-circle-in-cartesian

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!