Get rgl view parameters Get rgl view parameters r r

Get rgl view parameters


I've been trying to work this out myself and I think I have the answer for maintaining the perspective of a user modified interactive plot. view3d only affects the perspective within an already open window, the key is to use open3d to set-up your window and perspectives before you actually generate the plot.

In other words, we don't actually need to use the phi and theta angle information (directly). Once you have generated an interactive plot and got the perspective you like (you'll probably want to resize the window or the image grab will be too small), something like the following will extract the required information:

zoom<-par3d()$zoomuserMatrix<-par3d()$userMatrixwindowRect<-par3d()$windowRect

Then the following will open a window at the desired size and perspective (and zoom), generate the plot, and then grab the image.

open3d(zoom = zoom, userMatrix = userMatrix, windowRect=windowRect)perps3d(x=x,y=y,z=z) # plus whatever arguments you need, but ignoring all perspective argumentsrgl.snapshot( filename, fmt="png", top=TRUE)

That's the basic idea and can be used to automatically generate graphs of the same perspective. You can also mess around with the scale or fov arguments from par3d as you see fit, with the same sort of idea to extract and use the information. I think these are what will be required for Ali above.

It's a little inelegant to call persp3d when automatically generating multiple plots, because that function is really designed for interactive plots. I suspect you can use the information userMatrix, zoom, fov, scale etc from par3d, and some maths (such as Ali's) to determine phi, theta, r and d, and put these into persp directly - rather than dealing with persp3d for every plot, but I haven't tested that.


There is no need to extract the viewing angles. You can extract userMatrix

um <- par3d()$userMatrix

and then use

view3d(userMatrix = um)

The viewing angles will be restored.