Because in this case there is no curve on the line that you could use very simply (which emphasizes how the polygon works).
x <- c(0,1,1,0) y <- c(x[1:2]/2, x[3:4]/4) polygon(x,y, col = 'green', border = NA)
Now, if you have a curve, you will need more vertices.
curve(x^2, from=0 , to =1, col="darkblue") curve(x^4, from=0 , to =1, add=T, col="darkred") x <- c(seq(0, 1, 0.01), seq(1, 0, -0.01)) y <- c(x[1:101]^2, x[102:202]^4) polygon(x,y, col = 'green', border = NA)
(expand the range of this last curve and see how intersection curves themselves are processed using a similar code)
source share