Shading area between two curves

I can not imagine how a polygon works. I searched a lot, but I can’t understand how the polygon wants to get x, y and what they represent.

Can someone please help me and explain how to shade, for example, the area between the red and blue lines.

curve(x/2, from=0 , to =1, col="darkblue") curve(x/4, from=0 , to =1, add=T, col="darkred") 

thanks a lot

+4
source share
1 answer

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)

+9
source

Source: https://habr.com/ru/post/1393511/


All Articles