[R] rgl: axis/viewport/box problems in persp3d()

Marius Hofert m_hofert at web.de
Fri Sep 9 15:20:09 CEST 2011


Dear Duncan,

thanks a lot. 
Is it possible to rotate the label drawn by mtext3d, say, by 90 degrees? [a "rot=90" did not help]

Cheers,

Marius

On 2011-09-09, at 14:32 , Duncan Murdoch wrote:

> On 09/09/2011 8:02 AM, Marius Hofert wrote:
>> Dear Duncan,
>> 
>> thanks for your quick response.
>> Below is my second trial. I had to use mtext3d to place the label for the z-axis
>> at the new axis where the ticks are drawn (if there's a simpler solution, please
>> let me know). Was the usage of rgl.viewpoint meant this way?
> 
> I would have used par3d(zoom=pl$zoom, ... ) instead of rgl.viewpoint, but it probably gives the same result.  You'd have to check the sources.
> 
>>  It is nice to
>> adjust the rotation of the plotted object by hand but then I want to make sure
>> the subsequent plot(s) have precisely the same rotation.
>> 
>> Okay, great.
>> 
>> One more thing I am wondering is: I tried to pass through arguments like
>> marklen or expand to rgl.bbox/bbox3d. Is anything like this possible? I would like
>> to change the length of the axis ticks.
> 
> You can use marklen in bbox3d, but it won't affect the axes that were drawn with axes3d.  This is something that has been on my todo-list for a long time, uniting the two different ways of drawing axes (static ones from axes3d, dynamic ones from bbox3d).  To modify the static tick length, you'll need to modify the source to axis3d.
>> Cheers&  many thanks,
>> 
>> Marius
>> 
>> PS: I read somewhere that plotmath-expressions are not available in rgl. Is there
>> an update on this? I know it may be very difficult to implement this, I'm just
>> wondering if there is an update/workaround on this (?)
> 
> No, unfortunately not.   That's also on my todo-list, but fairly far down.  (I wouldn't implement plotmath in rgl; I would implement a standard graphics driver in rgl, so all graphics functions could draw to a plane in 3d space.  But that's really a lot of work.)
> 
> Duncan Murdoch
> 
>> require(rgl)
>> s<- seq(0, 1, length.out=21)
>> M<- function(u) apply(u, 1, min)
>> u<- s
>> v<- s
>> z<- outer(u, v, function(u,v) M(cbind(u,v)))
>> persp3d(u, v, z, aspect="iso", front="line", lit=FALSE, axes=FALSE, xlab="",
>>         ylab="", zlab="")
>> axes3d(edges=c('x--','y--','z+-')) # label the right axes
>> title3d(xlab="x", ylab="y", zlab="") # put in axes labels [z is wrong]
>> mtext3d("z", edge='z+-', line=2) # put in z-axis label by hand
>> par3d(windowRect=c(0,0,480,480), zoom=1.2) # use zoom to get everything on the viewport; then adjust rotation by hand
>> pl<- par3d(c("userMatrix", "zoom", "FOV")) # record for use in other plots
>> rgl.postscript("myplot.pdf", fmt="pdf") # print to file
>> rgl.viewpoint(zoom=pl$zoom, fov=pl$FOV, userMatrix=pl$userMatrix, interactive=FALSE) # set the viewpoint for the next plot to make sure it looks the same
>> 
>> On 2011-09-09, at 12:41 , Duncan Murdoch wrote:
>> 
>> >  On 11-09-09 6:18 AM, Marius Hofert wrote:
>> >>  Dear expeRts,
>> >>
>> >>  I am a new user of rgl, below is my first trial to plot a simple function in 3d.
>> >>  I managed to put the axes in the right locations, but:
>> >>  (1) The xlab, ylab, and zlab arguments are ignored; how can I put in axes labels?
>> >
>> >  Those are documented on the axes3d page, but are arguments to title3d, not axes3d.  So add title3d(xlab="x", etc.
>> >
>> >>  (2) Since I removed the axes in persp3d() the viewport is too small; is it possible
>> >>      to keep the size of the viewport?
>> >
>> >  You can manually adjust it to your taste, then write down the value of par3d("zoom").  Later you can reproduce the resizing by calling par3d(zoom=<saved value>  ).
>> >
>> >
>> >>  (3) The box is not correctly drawn, there are two "holes", one in (0,0,1) and one
>> >>      in (1,1,0); how can I fix that?
>> >
>> >  That happens because OpenGL has a limit on the range of depths that can be displayed, and the corners of the box have been adjusted to be too close or far.  This is arguably a bug in rgl, but it's sometimes a feature.
>> >
>> >  What I'd suggest is that you don't use rgl.viewpoint, you just manually adjust the display as you like, without making it quite as extreme, then record the values of par3d(c("userMatrix", "zoom", "FOV")); those control the viewpoint.
>> >
>> >  Duncan Murdoch
>> >
>> >>
>> >>  Cheers,
>> >>
>> >>  Marius
>> >>
>> >>
>> >>  require(rgl)
>> >>  s<- seq(0, 1, length.out=21)
>> >>  M<- function(u) apply(u, 1, min)
>> >>  u<- s
>> >>  v<- s
>> >>  z<- outer(u, v, function(u,v) M(cbind(u,v)))
>> >>  persp3d(u, v, z, aspect="iso", front="line", lit=FALSE, axes=FALSE, xlab="",
>> >>          ylab="", zlab="")
>> >>  axes3d(edges=c('x--','y--','z+-'), xlab="x", ylab="y", zlab="z")
>> >>  par3d(windowRect=c(0,0,480,480))
>> >>
>> >>  R1<- rotationMatrix(-55*pi/180, 1,0,0)
>> >>  R3<- rotationMatrix(50*pi/180, 0,0,1)
>> >>  R<- R1 %*% R3
>> >>  rgl.viewpoint(interactive=TRUE, userMatrix=R) # rotate
>> >>  rgl.postscript("myplot.pdf", fmt="pdf")
>> >>  ______________________________________________
>> >>  R-help at r-project.org mailing list
>> >>  https://stat.ethz.ch/mailman/listinfo/r-help
>> >>  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> >>  and provide commented, minimal, self-contained, reproducible code.
>> >
>> 
> 



More information about the R-help mailing list