bezierCurve <- function(x, y, n=100){
outx <- NULL
outy <- NULL
i <- 1
for (t in seq(0, 1, length.out=n)){
b <- bez(x, y, t)
outx[i] <- b$x
outy[i] <- b$y
i <- i+1
}
return (list(x=outx, y=outy))
}
bez <- function(x, y, t){
outx <- 0
outy <- 0
n <- length(x)-1
for (i in 0:n){
outx <- outx + choose(n, i)*((1-t)^(n-i))*t^i*x[i+1]
outy <- outy + choose(n, i)*((1-t)^(n-i))*t^i*y[i+1]
}
return (list(x=outx, y=outy))
}
plot.new()
plot.window(xlim=c(-3, 3), ylim=c(-3, 3), xaxs='i', yaxs='i')
rect(-5, -5, 0, 0, border=NA, col='#7fc97f')
rect(0, -5, 5, 0, border=NA, col='#beaed4')
rect(-5, 0, 0, 5, border=NA, col='#fdc086')
rect(0, 0, 5, 5, border=NA, col='#ffff99')
box(lwd=0.1)
#points(myData$x, myData$y, "o", pch=20, cex=0.8)
points(bezierCurve(myData$x, myData$y), type="l",
col= matlab.like(length(myData$frame)-1))