2 条曲线之间的阴影区域 [英] Shade area between 2 curves

查看:61
本文介绍了2 条曲线之间的阴影区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法理解polygon()是如何工作的.我已经搜索了很多,但我似乎无法理解多边形如何想要 x、y 点以及它们代表什么.

I can't seem to wrap my mind arround how polygon() works. I've searched a lot but I cant seem to understand how polygon wants the x,y points and what do they represent.

有人可以帮我解释一下如何遮蔽例如红线和蓝线之间的区域

Could someone please help me and explain how to shade for example the area between the red and blue line

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

非常感谢

推荐答案

因为,在这种情况下,直线实际上没有任何曲线,您可以使用一些非常简单的东西(突出显示多边形的工作原理).

Because, in this case, there isn't really any curve to the line you could use something very simple (that highlights how 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 had a curve you'd 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)

(扩大最后一条曲线的范围,看看使用类似的代码如何自己处理交叉曲线)

(extend the range of that last curve and see how using similar code treats the crossing curves yourself)

这篇关于2 条曲线之间的阴影区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆