Heart Curve

今天看了一下R语言,感觉还是很强大的,做了几个小例子,比如这几个画心形曲线的:

dat<- data.frame(t=seq(0, 2*pi, by=0.1) )
xhrt <- function(t) 16*sin(t)^3
yhrt <- function(t) 13*cos(t)-5*cos(2*t)-2*cos(3*t)-cos(4*t)
dat$y=yhrt(dat$t)
dat$x=xhrt(dat$t)
with(dat, plot(x,y, type="l"))
with(dat, polygon(x,y, col="hotpink"))
MASS::eqscplot(0:1,0:1,type="n",xlim=c(-1,1),ylim=c(-0.8,1.5))
curve(4/5*sqrt(1-x^2)+sqrt(abs(x)),from=-1,to=1,add=TRUE,col=2)
curve(4/5*-sqrt(1-x^2)+sqrt(abs(x)),from=-1,to=1,add=TRUE,col=2)

这两个的区别,主要是公式不一样,还有其他的公式,可以查看这里:
Heart Curve

还有用符号直接画的:

hearts <- expression(symbol('\251'))
plot( 0, xlim=c(0,2), ylim=c(0,2), type="n" )
text( 1, 1, hearts , col="red", cex=30 )  
plot(1, 1, pch = "♥", cex = 20, xlab = "", ylab = "", col = "red")

Comments are closed.