在R中绘制3D区域 [英] Plotting 3D region in R

查看:81
本文介绍了在R中绘制3D区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个变量, x y z ,我想在3D图中绘制以下区域(阴影):

I have three variables, x, y and z, and I would like to plot the following region (shaded) in a 3D plot:

1< x < 4、5< & 10,-6< z< -2

有什么办法可以做到吗?

Is there any way I can do that?

谢谢!

推荐答案

下面是代码:

library(rgl)
c3d <- cube3d(color="red",alpha=.1)
c3d$vb[1,] <- c3d$vb[1,] *1.5+2.5
c3d$vb[2,] <- c3d$vb[2,] *2.5+7.5
c3d$vb[3,] <- c3d$vb[3,] * 2 - 4
shade3d(c3d)
axes3d()

棘手的一点:原始的立方体 c3d 为-1< = x,y,z< = 1。 c3d $ vb 作为8列。我将原始角转换为新角。例如,关于x轴( c3d $ vb 的第一行),我们想将(-1,1)转换为(1,4)。这是通过(4-1)/(1-(-1))= 1.5的系数完成的,它将(-1,1)转换为(-1.5,1.5)。然后通过添加4-1.5 = 2.5,我们将得到(1,4)。

The tricky point: the original cube c3d is -1 <= x,y,z <= 1. The corners are listed in c3d$vb as 8 columns. I converted the original corners to the new corners. For instance about the x-axis (first row of c3d$vb) we want to convert (-1,1) to (1, 4). This is done by a factor of (4-1)/(1-(-1))=1.5, which converts (-1,1) to (-1.5, 1.5). Then by adding 4-1.5 = 2.5 we will have (1,4).

如果您有兴趣在绘图中添加坐标轴原点,则可以在shade3d(c3d)之前添加plot3d(0,0,0)-我相信对此有更好的解决方案-并且您将拥有:

If you are interested to have the axes origin in your plot, you may add plot3d(0,0,0) before shade3d(c3d) - I am sure there are better solutions to this - and you will have:

这篇关于在R中绘制3D区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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