欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

pyhthon繪制超炫酷的心形線星形線擺線

 更新時間:2021年10月19日 11:14:30   作者:微小冷  
這篇文章主要為大家介紹了如何用pyhthon繪制各種超炫酷的擺線,本文主要實現(xiàn)了心形線和星形線也就是外擺線和內擺線兩種,有需要的朋友可以借鑒參考下

擺線

最簡單的旋輪線就是擺線,指圓在直線上滾動時,圓周上某定點的軌跡。

設圓的半徑為 r ,在x軸上滾動  x距離則意味著旋轉了 x \ r​ 弧度,則其滾動所產生的擺線如下

在這里插入圖片描述

r = 1
theta = np.arange(0,6.4,0.1)
xCircle0 = np.cos(theta)
yCircle0 = 1+np.sin(theta)
fig = plt.figure(figsize=(15,4))
ax = fig.add_subplot(autoscale_on=False, 
    xlim=(1,10),ylim=(0,2))
ax.grid()
circle, = ax.plot(xCircle0,yCircle0,'-',lw=1)
point, = ax.plot([1],[1],'o')
trace, = ax.plot([],[],'-', lw=1)
theta_text = ax.text(0.02,0.85,'',transform=ax.transAxes)
textTemplate = '''x = %.1f°\n'''
xs,ys = [], []
def animate(x):
    if(x==0):
        xs.clear()
        ys.clear()
    xCycloid = x + r*np.cos(-x) #由于是向右順時針滾,所以角度為負
    yCycloid = 1 + r*np.sin(-x)
    xCircle = xCircle0+x
    xs.append(xCycloid)
    ys.append(yCycloid)
    circle.set_data(xCircle,yCircle0)
    point.set_data([xCycloid],[yCycloid])
    trace.set_data(xs,ys)
    theta_text.set_text(textTemplate % x)
    return circle, point, trace, theta_text
frames = np.arange(0,10,0.02)
ani = animation.FuncAnimation(fig, animate, frames, 
    interval=5, blit=True)
ani.save("Cycloid.gif")
plt.show()

如果選取圓內或圓外的一點描成軌跡,則為次擺線,圓外點的軌跡為長幅擺線,

在這里插入圖片描述

反之則為短幅擺線

在這里插入圖片描述

代碼

r = 1
rIn = 0.5
theta = np.arange(0,6.4,0.1)
xCircle0 = np.cos(theta)
yCircle0 = 1+np.sin(theta)
xCircleOut0 = rIn*np.cos(theta)
yCircleOut0 = 1+rIn*np.sin(theta)
fig = plt.figure(figsize=(20,3))
ax = fig.add_subplot(autoscale_on=False, 
    xlim=(1,15),ylim=(0,2))
ax.grid()
circle, = ax.plot(xCircle0,yCircle0,'-',lw=1)
circleOut, = ax.plot(xCircleOut0,yCircleOut0,linestyle='--',lw=1)
point, = ax.plot([1],[1],'o')
pointOut, = ax.plot([1],[1.5],'o')
trace, = ax.plot([],[],'-', lw=1)
theta_text = ax.text(0.02,0.85,'',transform=ax.transAxes)
textTemplate = '''x = %.1f\n'''
xs,ys = [], []
def animate(x):
    if(x==0):
        xs.clear()
        ys.clear()
    xCycloid = x + r*np.cos(-x)
    yCycloid = 1 + r*np.sin(-x)
    xCycloidOut = x + rIn*np.cos(-x)
    yCycloidOut = 1 + rIn*np.sin(-x)
    xs.append(xCycloidOut)
    ys.append(yCycloidOut)
    circle.set_data(xCircle0+x,yCircle0)
    circleOut.set_data(xCircleOut0+x,yCircleOut0)
    point.set_data([xCycloid],[yCycloid])
    pointOut.set_data([xCycloidOut],[yCycloidOut])
    trace.set_data(xs,ys)
    theta_text.set_text(textTemplate % x)
    return circle, circleOut, point, pointOut, trace, theta_text
frames = np.arange(0,15,0.1)
ani = animation.FuncAnimation(fig, animate, frames, 
    interval=50, blit=True)
ani.save("Cycloid.gif")
plt.show()

在這里插入圖片描述

隨著 λ 的變化,圖像的變化過程為

在這里插入圖片描述

外擺線和心臟線

如果在一個圓繞著另一個固定的圓滾動,如果在圓外滾動,則動圓上的某相對固定點的軌跡為外擺線;若在圓內滾動,則某點的軌跡為內擺線。設定圓半徑為 a ,動圓半徑為 b ,則繞行旋轉  t度后,動圓圓心圓心位置為

在這里插入圖片描述

在這里插入圖片描述

若選點 ( a , 0 ) 作為起點,則外擺線的參數(shù)方程為

在這里插入圖片描述

a = b 時就得到了著名的心臟線,被許多直男奉為經(jīng)典

在這里插入圖片描述

a = 1
b = 1
theta = np.arange(0,6.4,0.05)
fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot(autoscale_on=False, 
    xlim=(-3,3),ylim=(-3,3))
theta_text = ax.text(0.02,0.85,'',transform=ax.transAxes)
textTemplate = '''θ = %.1f°\n'''
ax.grid()
xCircle,yCircle = np.cos(theta),np.sin(theta)
ax.plot(a*xCircle,a*yCircle,'-',lw=1)
pt, = ax.plot([a+b],[0],'*')
cir, = ax.plot(a+b+b*yCircle,b*yCircle,'-',lw=1)
cycloid, = ax.plot([], [], '-', lw=1)
xs,ys = [],[]
def animate(t):
    if(t==0):
        xs.clear()
        ys.clear()    
    cenX = (a+b)*np.cos(t)
    cenY = (a+b)*np.sin(t)
    cir.set_data(cenX+b*xCircle,cenY+b*yCircle)
    newX = cenX - b*np.cos((a+b)/b*t)
    newY = cenY - b*np.sin((a+b)/b*t)
    xs.append(newX)
    ys.append(newY)
    pt.set_data([newX],[newY])
    cycloid.set_data(xs,ys)
    theta_text.set_text(textTemplate % t)
    return cycloid, cir, pt, theta_text
ani = animation.FuncAnimation(fig, animate, theta, 
    interval=50, blit=True)
ani.save("Cycloid.gif")
plt.show()

如果更改 a \ b比值,則可得到

 a \ b=2

在這里插入圖片描述 

 a \ b​=5

在這里插入圖片描述 

 a \ b=1\2

在這里插入圖片描述

 a \ b​=2\3​

在這里插入圖片描述

對 a\b進行約分得到 m \ n​,曲線由 m支組成,總共繞定圓 n周,然后閉合。觀察 1 \b = 1 \2 時的曲線,可以看到其前 p i 個值和后 π 個值組成的心形更好看。

如果 a\b​是無理數(shù),則永遠也不會閉合,例如令 b = e ,由于圖片超過5M,所以就不上傳了。這個圖總共轉了17圈,到后期十分考驗視力,為了讓規(guī)律更清晰,我們選擇只繪制尖點附近的運動狀態(tài),

在這里插入圖片描述

內擺線與星形線

當動圓在定圓內部轉動時,則為內擺線,其方程為

在這里插入圖片描述

a\b​=2

在這里插入圖片描述 

a\b​=4

在這里插入圖片描述 

a\b=5

在這里插入圖片描述 

a \b = 1\3

在這里插入圖片描述

當 a \b = 4 時,其方程可化簡為

在這里插入圖片描述

被稱為星形線。

接下來按照慣例,畫一下隨著 a\ b 比值的變化,內外擺線形狀的變化過程

外擺線

在這里插入圖片描述

內擺線

在這里插入圖片描述

代碼如下

#test.py
import argparse     #用于命令行的交互
parser = argparse.ArgumentParser()
parser.add_argument('bStart', type=float)
parser.add_argument('bEnd', type=float)
args = parser.parse_args()
a = 1
bStart = args.bStart
bEnd = args.bEnd
fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot(autoscale_on=False, 
    xlim=(-(a+2*bEnd),(a+2*bEnd)),ylim=(-(a+2*bEnd),(a+2*bEnd)))
theta_text = ax.text(0.02,0.85,'',transform=ax.transAxes)
textTemplate = '''a=1, b= %.2f\n'''
ax.grid()
t = np.arange(0,6.4,0.05)
ax.plot(a*np.cos(t),a*np.sin(t),'-',lw=1)
cycloid, = ax.plot([], [], '-', lw=1)
xs,ys = [],[]
t = np.arange(0,30,0.05)
def animate(b):    
    xs = (a+b)*np.cos(t) - b*np.cos((a+b)/b*t)
    ys = (a+b)*np.sin(t) - b*np.sin((a+b)/b*t)
    cycloid.set_data(xs,ys)
    theta_text.set_text(textTemplate % b)
    return cycloid, theta_text
ani = animation.FuncAnimation(fig, animate, np.arange(bEnd,bStart,-0.02), 
    interval=50, blit=True)
plt.show()
ani.save("Cycloid.gif")

在命令行中輸入

python test.py -2 2

內擺線和外擺線同常規(guī)的擺線一樣,皆具有對應的長輻或短輻形式,其標準方程為

在這里插入圖片描述

當 b > 0時為外擺線, b < 0時為內擺線,對于星形線而言,其變化過程如圖所示

在這里插入圖片描述

以上就是pyhthon繪制超炫酷的心形線星形線擺線的詳細內容,更多關于pyhthon繪制心形星形線擺線的資料請關注腳本之家其它相關文章!

相關文章

  • Python與xlwings黃金組合處理Excel各種數(shù)據(jù)和自動化任務

    Python與xlwings黃金組合處理Excel各種數(shù)據(jù)和自動化任務

    這篇文章主要為大家介紹了Python與xlwings黃金組合處理Excel各種數(shù)據(jù)和自動化任務示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪<BR>
    2023-12-12
  • Python httplib模塊使用實例

    Python httplib模塊使用實例

    這篇文章主要介紹了Python httplib模塊使用實例,httplib模塊是一個底層基礎模塊,本文講解了httplib模塊的常用方法及使用實例,需要的朋友可以參考下
    2015-04-04
  • python保存圖片時如何和原圖大小一致

    python保存圖片時如何和原圖大小一致

    這篇文章主要介紹了python保存圖片時如何和原圖大小一致問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-11-11
  • Windows下的Python 3.6.1的下載與安裝圖文詳解(適合32位和64位)

    Windows下的Python 3.6.1的下載與安裝圖文詳解(適合32位和64位)

    這篇文章主要介紹了Windows下的Python 3.6.1的下載與安裝圖文詳解(適合32位和64位),需要的朋友可以參考下
    2018-02-02
  • python實現(xiàn)媒體播放器功能

    python實現(xiàn)媒體播放器功能

    這篇文章主要為大家詳細介紹了python實現(xiàn)媒體播放器功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-02-02
  • Python多線程實現(xiàn)支付模擬請求過程解析

    Python多線程實現(xiàn)支付模擬請求過程解析

    這篇文章主要介紹了python多線程實現(xiàn)支付模擬請求過程解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-04-04
  • 關于pandas.date_range()的用法及說明

    關于pandas.date_range()的用法及說明

    這篇文章主要介紹了關于pandas.date_range()的用法及說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-07-07
  • 淺談python 四種數(shù)值類型(int,long,float,complex)

    淺談python 四種數(shù)值類型(int,long,float,complex)

    下面小編就為大家?guī)硪黄獪\談python 四種數(shù)值類型(int,long,float,complex)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-06-06
  • 使用PyQtGraph繪制精美的股票行情K線圖的示例代碼

    使用PyQtGraph繪制精美的股票行情K線圖的示例代碼

    這篇文章主要介紹了使用PyQtGraph繪制精美的股票行情K線圖的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-03-03
  • Python openpyxl模塊實現(xiàn)excel讀寫操作

    Python openpyxl模塊實現(xiàn)excel讀寫操作

    這篇文章主要介紹了Python openpyxl模塊實現(xiàn)excel讀寫操作,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-06-06

最新評論