用R語言畫蝴蝶曲線蝴蝶曲線的極坐標(biāo)方程為 參數(shù)取值范圍為。 寫成參數(shù)方程,為
參數(shù)取值范圍與極坐標(biāo)下是相同的。一般為了追求曲線多一些變化,往往把改寫成。 這些天不少文章用matlab、mathematica、maple、python語言,甚至scratch、VBA等繪制它,卻唯獨少了R語言。然而R語言在可視化的表現(xiàn)力方面是相當(dāng)相當(dāng)強大的。下面用R來畫蝴蝶曲線。 在參數(shù)方程下用ggplot2包繪制t<-seq(from = 0, to = 12*pi, by = 0.005) x<-sin(t)*(exp(cos(t)) - 2*cos(4*t)-(sin(t/11))^5) y<-cos(t)*(exp(cos(t)) - 2*cos(4*t)-(sin(t/11))^5) mydata<-data.frame(x = x, y = y) library(ggplot2) ggplot(data = mydata,aes(x = x, y = y))+ geom_point(colour = 'blue')+ coord_cartesian()

在參數(shù)方程下直接使用plot低水平函數(shù)繪制
t<-seq(from = 0, to = 12*pi, by = 0.005) x<-sin(t)*(exp(cos(t)) - 2*cos(4*t)-(sin(t/11))^5) y<-cos(t)*(exp(cos(t)) - 2*cos(4*t)-(sin(t/11))^5) mydata<-data.frame(x = x, y = y) par(mfrow=c(2,1)) plot(x,y,"s",col="blue") plot(x,y,"h",col="cyan2")

極坐標(biāo)方程下用IDPmisc極坐標(biāo)轉(zhuǎn)直角坐標(biāo)
t<-seq(from = 0, to = 12*pi, by = 0.005) r <-exp(cos(t))-2*cos(4*t)+(sin(t/12))^5 library(IDPmisc) #小心IDPmisc極坐標(biāo)轉(zhuǎn)直角坐標(biāo)的phi用度作為角單位 xy <- clock2cart(rho=r,phi=t/pi*180,circle=-360)
library(ggplot2) ggplot(data = xy,aes(x = x, y = y))+ geom_point(colour = 'red')

把直角坐標(biāo)彎曲對應(yīng)到平面圓里面
t<-seq(from = 0, to = 12*pi, by = 0.005) r <-exp(cos(t))-2*cos(4*t)+(sin(t/12))^5 library(IDPmisc) #小心IDPmisc極坐標(biāo)轉(zhuǎn)直角坐標(biāo)的phi用度作為角單位 xy <- clock2cart(rho=r,phi=t/pi*180,circle=-360)
library(ggplot2) ggplot(data = xy,aes(x = x, y = y))+ geom_point(colour = 'red')+ coord_polar()

|