- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 rgl 交互地选择合适的视点,然后在格子 3d 图中采用相同的方向会很方便。例如,使用非信息性观点给出以下图。
library(lattice)
wireframe(volcano, screen = list(x=0, y=0, z=0))
可以通过
在rgl
中打开相同的内容
library(rgl)
persp3d(volcano)
view3d(0, 0)
以交互方式,可以轻松地将绘图旋转到信息丰富的 View 。
给出当前rgl
视点的矩阵可以通过以下方式提取
p <- par3d()
p$userMatrix
如何将这个矩阵转换成对应的x
,y
,z
screen
参数来复制点阵中的 View ?
更新1
我在下面尝试了 42 的转换。该代码显示了 rgl 图和每行相应的格子图。如果我正确实现了它(参见下面的代码),似乎仍然存在问题。
# convert rgl viewpoint into lattice
# screen orientation
rgl_to_lattice_viewpoint <- function()
{
p <- par3d()
rotm <- p$userMatrix
B = 360*atan(rotm[1,2]/rotm[2,2])/(2*pi)
P = 360*asin(-rotm[3,2])/(2*pi)
H = 360*atan(rotm[3,1]/rotm[3,3])/(2*pi)
list(x=-B, y=-P, z=-H)
}
# read and plot PNG image
plot_png <- function(f)
{
img <- readPNG(f)
rimg <- as.raster(img) # raster multilayer object
plot(NULL, xlim=c(0,1), ylim=c(0,1), xlab = "", ylab = "",
asp=1, frame=F, xaxt="n", yaxt="n")
rasterImage(rimg, 0, 0, 1, 1)
}
# create rgl snapshot with random rotation and
# corresponding lattice wireframe plot
lattice_plus_rgl_plot <- function()
{
# rgl plot random rotation
persp3d(volcano, col = "green3")
theta <- sample(-180:180, 1)
phi <- sample(-90:90, 1)
view3d(theta, phi, fov=40)
v <- rgl_to_lattice_viewpoint()
f <- tempfile(fileext = ".png")
rgl.snapshot(f)
rgl.close()
# lattice plot
f2 <- tempfile(fileext = ".png")
png(f2)
print(wireframe(volcano, screen = v))
dev.off()
# plot both
plot_png(f)
plot_png(f2)
}
# CREATE SOME PLOTS
library(rgl)
library(lattice)
library(png)
par(mfrow=c(3,2), mar=c(0,0,0,0))
replicate(3, lattice_plus_rgl_plot())
最佳答案
我使用这个问题的答案来将旋转矩阵转换为角度:Conversion euler to matrix and matrix to euler 。我承认担心我在这里看到另一个有些不同的答案:How to calculate the angle from Roational matrix 。 (我的线性代数不足以确定哪个是正确的。)
p <- par3d()
rotm <- p$userMatrix
B = 360*atan(rotm[1,2]/rotm[2,2])/(2*pi)
P = 360*asin(-rotm[3,2])/(2*pi)
H = 360*atan(rotm[3,1]/rotm[3,3])/(2*pi)
> print(list(B,P,H))
[[1]]
[1] 41.54071
[[2]]
[1] 40.28412
[[3]]
[1] 41.24902
那时我已经将 RGL 对象旋转到了您建议的大致“观察点”。我通过实验发现,提供给线框调用的负值提供了明显正确的结果。 “观察者旋转角度”似乎被视为“对象旋转角度”的负数。
png(); print(wireframe(volcano, screen = list(x=-B, y=-P, z=-H)) ); dev.off()
TeachingDemos 包中有一个 rotate.wireframe
函数,但它不能很好地处理同时运行的 rgl 图。 (在我关闭 rgl 设备之前,没有明显的情节。)在 Mac 上运行时,它似乎也有一些问题(格子图上有粗黑线)。它使用 X11/XQuartz 设施通过 tk/tcl 函数管理交互,我无法从显示的角度重现绘图。看看代码我无法理解为什么会这样。但您的里程可能会有所不同。
关于在点阵中复制 rgl 视点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37007722/
rgl 包过去是在 R-forge 上开发的 https://r-forge.r-project.org/projects/rgl/ .安装最新版本的方法是 install.packages("rgl
rgl.cur() 返回当前 rgl 设备编号,rgl.set() 允许将设备设置为事件设备。我找不到返回所有打开的设备的 rgl 函数,例如用于标准图形设备的 dev.list()。是否有我错过的功
rgl.postscript() 不应该用于 headless 服务器,即当 options(rgl.useNULL = TRUE) 时?我知道 rgl.snapshot() 不起作用。 librar
我正在尝试创建一个显示 RGL 可视化效果的 Shiny 应用程序(这只不过是一组抛光的棍子和球体)。请查看下面的可视化代码 library(rgl) library(tidyverse) spher
正在做(R3.4,ubuntu 16.04,rgl 0.95.1441): library(rgl) open3d() 返回: Error in rgl.clear(type, subscen
为了演示 3D 中线性变换的效果 x -> A x ,我想绘制一个立方体并在 A 下显示其变换。为此,我需要分别为每个面着色,并显示每个面的顶点和轮廓线。 我无法弄清楚如何为面部使用不同的颜色,以及如
我正在使用 plot3d() 绘制一些点数据。 我想让我的 y 轴刻度标签更靠近我的 y 轴刻度线。 我能想到的最好的方法是 1)先绘制数据,不绘制轴 2) 调用axis3d() 绘制y 轴和刻度线,
我已尽可能多地关注此问题以解决问题,但没有成功。根本无法安装 R 包“rgl”。我已将 Ubuntu 服务器 16 升级到 R 版本 3.3.1。 PuTTY X11 proxy: Unsupport
使用 rgl 交互地选择合适的视点,然后在格子 3d 图中采用相同的方向会很方便。例如,使用非信息性观点给出以下图。 library(lattice) wireframe(volcano, scree
我使用 scatter3d() 和 Rcmdr 创建了一个漂亮的图。该图包含两个漂亮的表面平滑度。现在我想向该图添加另一个表面,真相(即由生成我的观察值的函数定义的表面减去噪声分量)。 到目前为止,这
我想使用 rgl 来绘制圆锥体的一部分,如 this web page (点击“3d锥体模型”) 我想指定三个参数(底部半径、顶部半径、高度),然后在 rgl 中绘制一个圆锥体——这可能/容易吗?如何
我使用选项 --disable-libpng 安装了 rgl 包。我尝试生成一个 3d 散点图,但它崩溃了。请帮我解决这个问题 这是我正在运行的代码 library(rgl) open3d() x
从@DWin和@Ben Bolker,我们可以在R中更改scatter3d函数以绘制“更漂亮”(http://stackoverflow.com/questions/8204972/carscatte
我想使用plot3d()( rgl )绘制3维MDS分析的结果。数据和代码如下所示: threedim$points [,1] [,2] [,
当我使用包含文本和深色背景的 OpenGL 输出 rgl 场景时,文本无法正确显示。 示例代码: library(rgl); library(htmlwidgets) open3d() bg3d(co
有没有人在 Rstudio(版本 0.99.489)中使用 R rgl 包(版本 0.95.1201)?每次打电话library(rgl) ,Rstudio 崩溃。 更新 我通过从源代码安装版本 0.
我的系统环境: Mac操作系统10.10.2 X11(XQuartz 2.7.5) R 3.1.2 当我加载并使用“rgl”包时,我收到以下错误消息。 > library("rgl",lib.loc=
我使用 rgl 包为数据的每个因子级别生成了 3D 图,并将它们保存为 png。我的数据有 30 个不同的级别,从而产生了 30 个不同的图像文件。现在我想将这些 png 合并到一个图中。 我会这样显
我正在使用 rgl 包来渲染许多形状,但是我遇到了一个问题,即不同视点的反射/眩光量可能会分散注意力。我确信有一些属性需要改变才能使光源成为环境而不是定向。我尝试使用以下选项: clear3d(typ
尝试在 arch linux x86_64 上为 r 编译 rgl。我只复制了安装的错误部分。这发生在我最近更新 R 之后。知道如何解决这个问题吗? g++ -I/usr/include/R/ -DN
我是一名优秀的程序员,十分优秀!