最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

擺線

最簡(jiǎn)單的旋輪線就是擺線,指圓在直線上滾動(dòng)時(shí),圓周上某定點(diǎn)的軌跡。

設(shè)圓的半徑為 r ,在x軸上滾動(dòng)  x距離則意味著旋轉(zhuǎn)了 x \ r​ 弧度,則其滾動(dòng)所產(chǎn)生的擺線如下

在這里插入圖片描述

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) #由于是向右順時(shí)針滾,所以角度為負(fù)
    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()

如果選取圓內(nèi)或圓外的一點(diǎn)描成軌跡,則為次擺線,圓外點(diǎn)的軌跡為長(zhǎng)幅擺線,

在這里插入圖片描述

反之則為短幅擺線

在這里插入圖片描述

代碼

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()

在這里插入圖片描述

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

在這里插入圖片描述

外擺線和心臟線

如果在一個(gè)圓繞著另一個(gè)固定的圓滾動(dòng),如果在圓外滾動(dòng),則動(dòng)圓上的某相對(duì)固定點(diǎn)的軌跡為外擺線;若在圓內(nèi)滾動(dòng),則某點(diǎn)的軌跡為內(nèi)擺線。設(shè)定圓半徑為 a ,動(dòng)圓半徑為 b ,則繞行旋轉(zhuǎn)  t度后,動(dòng)圓圓心圓心位置為

在這里插入圖片描述

在這里插入圖片描述

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

在這里插入圖片描述

a = b 時(shí)就得到了著名的心臟線,被許多直男奉為經(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​

在這里插入圖片描述

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

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

在這里插入圖片描述

內(nèi)擺線與星形線

當(dāng)動(dòng)圓在定圓內(nèi)部轉(zhuǎn)動(dòng)時(shí),則為內(nèi)擺線,其方程為

在這里插入圖片描述

a\b​=2

在這里插入圖片描述 

a\b​=4

在這里插入圖片描述 

a\b=5

在這里插入圖片描述 

a \b = 1\3

在這里插入圖片描述

當(dāng) a \b = 4 時(shí),其方程可化簡(jiǎn)為

在這里插入圖片描述

被稱為星形線。

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

外擺線

在這里插入圖片描述

內(nèi)擺線

在這里插入圖片描述

代碼如下

#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

內(nèi)擺線和外擺線同常規(guī)的擺線一樣,皆具有對(duì)應(yīng)的長(zhǎng)輻或短輻形式,其標(biāo)準(zhǔn)方程為

在這里插入圖片描述

當(dāng) b > 0時(shí)為外擺線, b < 0時(shí)為內(nèi)擺線,對(duì)于星形線而言,其變化過程如圖所示

在這里插入圖片描述

以上就是pyhthon繪制超炫酷的心形線星形線擺線的詳細(xì)內(nèi)容,更多關(guān)于pyhthon繪制心形星形線擺線的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Elasticsearches的集群搭建及數(shù)據(jù)分片過程詳解

    Elasticsearches的集群搭建及數(shù)據(jù)分片過程詳解

    這篇文章主要為大家介紹了Elasticsearches的集群搭建及數(shù)據(jù)分片過程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-04-04
  • 將FileStorage對(duì)象高效轉(zhuǎn)換為NumPy數(shù)組的兩種實(shí)現(xiàn)方案

    將FileStorage對(duì)象高效轉(zhuǎn)換為NumPy數(shù)組的兩種實(shí)現(xiàn)方案

    在Web開發(fā)(如Flask應(yīng)用)中,處理用戶上傳的圖片文件時(shí),常會(huì)遇到FileStorage對(duì)象向numpy.ndarray的轉(zhuǎn)換需求,本文將提供兩種經(jīng)過驗(yàn)證的高效方法,并深入解析其技術(shù)細(xì)節(jié)與適用場(chǎng)景,需要的朋友可以參考下
    2025-03-03
  • python時(shí)間日期相加減的實(shí)現(xiàn)示例

    python時(shí)間日期相加減的實(shí)現(xiàn)示例

    在實(shí)際開發(fā)中,我們經(jīng)常需要對(duì)日期進(jìn)行加減操作,本文主要介紹了python時(shí)間日期相加減的實(shí)現(xiàn)示例,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-02-02
  • 簡(jiǎn)單談?wù)凱ython中函數(shù)的可變參數(shù)

    簡(jiǎn)單談?wù)凱ython中函數(shù)的可變參數(shù)

    和C語(yǔ)言一樣,Python中也有可變參數(shù)函數(shù),即一個(gè)函數(shù)可以接收多個(gè)參數(shù),而這些參數(shù)的個(gè)數(shù)在函數(shù)調(diào)用之前事先是不知道的。下面這篇文章我們來(lái)介紹下python中的可變參數(shù)
    2016-09-09
  • Python?class類@staticmethod及@classmethod區(qū)別淺析

    Python?class類@staticmethod及@classmethod區(qū)別淺析

    這篇文章主要為大家介紹了Python?class類@staticmethod及@classmethod區(qū)別淺析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-07-07
  • 詳解Python中的文件操作

    詳解Python中的文件操作

    這篇文章主要介紹了Python中文件操作的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)python,感興趣的朋友可以了解下
    2021-01-01
  • python調(diào)用cmd復(fù)制文件代碼分享

    python調(diào)用cmd復(fù)制文件代碼分享

    Python3調(diào)用cmd復(fù)制文件,win7下測(cè)試通過,大家參考使用吧
    2013-12-12
  • Python使用configparser讀取ini配置文件

    Python使用configparser讀取ini配置文件

    這篇文章主要介紹了Python使用configparser讀取ini配置文件,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-05-05
  • Python File(文件) 方法整理

    Python File(文件) 方法整理

    在本篇文章中我們給大家整理了關(guān)于Python File(文件) 的用法以及相關(guān)知識(shí)點(diǎn),有興趣的朋友們學(xué)習(xí)下。
    2019-02-02
  • python3 shelve模塊的詳解

    python3 shelve模塊的詳解

    這篇文章主要介紹了python3 shelve模塊的詳解的相關(guān)資料,需要的朋友可以參考下
    2017-07-07

最新評(píng)論

四平市| 锡林浩特市| 高雄市| 庄河市| 罗田县| 新泰市| 咸宁市| 太康县| 常熟市| 靖远县| 榆林市| 朝阳区| 体育| 蓬安县| 驻马店市| 合阳县| 宜昌市| 陇南市| 阿坝县| 宁国市| 祁连县| 台前县| 靖边县| 兰考县| 阳春市| 临夏县| 天气| 合肥市| 青海省| 永顺县| 石棉县| 青河县| 乌拉特后旗| 镇康县| 五大连池市| 泾川县| 浑源县| 伊金霍洛旗| 河西区| 军事| 太仆寺旗|