如何从R中的方程绘制平面 [英] How to plot a plane from an equation in R

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

问题描述

我一直在修改 RGL 包以弄清楚如何从 R 中的方程绘制平面,但无济于事.

I've been tinkering with the RGL package to figure out how to plot a plane from an equation in R, to no avail.

例如,我想可视化以下平面:

For example, I would like to visualize the following plane:

1x + 0y + 0z = 2
0x + 1y + 0z = 3
0x + 0y + 1z = 4

似乎 rgl 的 planes3d 函数只向现有的 3D 绘图添加了一个平面.

It seems the rgl's planes3d function only adds a plane to an existing 3D plot.

推荐答案

这是一个简单的例子:

library(rgl)
# Create some dummy data
dat <- replicate(2, 1:3)

# Initialize the scene, no data plotted
plot3d(dat, type = 'n', xlim = c(-1, 1), ylim = c(-1, 1), zlim = c(-3, 3), xlab = '', ylab = '', zlab = '') 

# Add planes
planes3d(1, 1, 1, 0, col = 'red', alpha = 0.6)
planes3d(1, -1, 1, 0, col = 'orange', alpha = 0.6)
planes3d(1, -1, -1, -0.8, col = 'blue', alpha = 0.6)

得到以下结果.

如您所见,从这样的情节中很难理解空间结构,但交互性当然会有所帮助.或者,您可以将平面绘制为线框,这有时有助于理解空间结构:

As you can see, it is quite hard to understand the spatial structure from such a plot, but the interactivity of course helps. Alternatively you can plot the planes as wireframes, which will sometimes help in understanding the spatial structure:

# Evaluate planes
n <- 20
x <- y <- seq(-1, 1, length = n)
region <- expand.grid(x = x, y = y)

z1 <- matrix(-(region$x + region$y), n, n)
z2 <- matrix(-region$x + region$y, n, n)
z3 <- matrix(region$x - region$y - 0.8, n, n)

surface3d(x, y, z1, back = 'line', front = 'line', col = 'red', lwd = 1.5, alpha = 0.4)
surface3d(x, y, z2, back = 'line', front = 'line', col = 'orange', lwd = 1.5, alpha = 0.4)
surface3d(x, y, z3, back = 'line', front = 'line', col = 'blue', lwd = 1.5, alpha = 0.4)
axes3d()

这篇关于如何从R中的方程绘制平面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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