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

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

问题描述

我有三个变量,xyz,我想在 3D 中绘制以下区域(阴影)情节:

<代码>1 <×<4、5<y<10、-6

有什么办法可以做到吗?

解决方案

代码如下:

库(rgl)c3d <- cube3d(color="red",alpha=.1)c3d$vb[1,] <- c3d$vb[1,] *1.5+2.5c3d$vb[2,] <- c3d$vb[2,] *2.5+7.5c3d$vb[3,] <- c3d$vb[3,] * 2 - 4阴影3d(c3d)轴3d()

棘手的一点:原始立方体 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).

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

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 < y < 10, -6 <z <-2

Is there any way I can do that?

解决方案

Here is the code:

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()

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).

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天全站免登陆