[R] RGL 'front' upwards default in rendering image
Duncan Murdoch
murdoch at stats.uwo.ca
Tue Oct 3 19:31:32 CEST 2006
On 10/3/2006 11:31 AM, Joe Byers wrote:
> thanks for the reply.
>
> I wish I could create a self contained example of the problem, but I can't.
>
> My task is displaying the surface generated from a simulation of Forward
> prices for a selected trajectory. The x axis is time from 9/25/06 to
> 3/31/2007 or 133X1 vector of integers. The z axis is the expiration
> month of the forwards as integers (1-36), the y axis is price. For each
> day(x) there are 36 prices (y). surface3d displays the surface but
> displays the z axis in reverse order and the x axis in reverse order as
> well. I can rotate the image 180 degrees but time on the x axis is
> running from right to left instead of left to right. My z axis is now
> in ascending order.
>
> I have read the documentation for rgl and much of the supported
> documents on neosciences web site, but I can not understand how to
> generate the image with the displaying the x axis left to right and z
> axis in ascending order. I think that rotation matrix or a setting in
> rgl.materials will do it, but I can't figure out which one. This
> mathematical conversions is beyond me.
Generally I'd suggest using surface3d, which uses the same conventions
as persp and other R functions, rather than rgl.surface, which uses the
OpenGL/computer graphics conventions.
If you do that, you would want x and y to be the fixed variables (rows
and columns) and z to be the response.
>
> Here is my code
> library(rgl);
> #set x and z vectors
> x<-as.numeric(as.date(rownames(calday.1),order='ymd'));
> z<-as.numeric(colnames(a)[1:ncurve]); #only use the portion of the curve
> with data, exclude NaN's
> res<-par3d('zoom'=5);
> #attempt to set the image/window size, constrained to
> 0,0,256,256 wish I could change this to 0,0,640,640
That's on my wish list too. All I can suggest is that in the current
release in Windows in MDI mode, the Windows|Tile command works.
(The difficulty is that rgl is portable to 3 incompatible windowing
systems. Things like setting the size of a Window thus take much more
work than you'd expect. More than three times as much, because I don't
think there's anybody who is familiar with all 3 systems.)
> res<- rotationMatrix(pi,0, 1, 0) # attempt to set rotation, does not
> make a difference
That just stored a matrix. You need to use view3d to set the userMatrix
to that value.
> #create a x labels vectors that somewhat matches in the image, trial and
> error here
> labels<-as.character(as.date(x))# could just use rownames(calday.1)
> labels<-labels[c(1,n%/%6,n%/%4,n%/%3,n%/%2,(n*2)%/%3,(n*3)%/%4,(n*5)%/%6,n)]
> i=1;
> y<-ez[,,i]; # set y array
> #create the y axis labels,again trial and error to fit, using 7
> slots from 0 to the max(y)
> labelsy<-as.character(format(max(y)*rep(1/7,8)*(seq(1:8)-1),digits=2))
> #pretty colors thank you rgl docs.
> ylim <- range(y)
> ylen <- ylim[2] - ylim[1] + 1
> colorlut <- terrain.colors(ylen) # height color lookup table
> col <- colorlut[ y-ylim[1]+1 ] # assign colors to heights for each point
> #generate the surface
> rgl.surface(x,z,y,ylim=c(0,max(ez[,,i])),back='lines',color=col)
> title3d(xlab='Date',zlab='Contract Month');#,ylab='Price $');
> #sub='Forward curve Trajectory 1',
> axis3d('x--',labels=labels,nticks=9)
> axis3d('y+-',labels=labelsy,nticks=8)
> axis3d('z--',labels=as.character(z),nticks=ncurve);
You can use the "at" argument to set ticks at some location and "labels"
to set the text to something else. For example, you might want to
reverse one of the axes if the direction isn't the one you want.
Duncan Murdoch
>
> Thank you
> Joe
>
> Duncan Murdoch wrote:
>> Joe Byers wrote:
>>> The documentation for surface3d and rgl.surface in the package RGL
>>> states
>>> "'surface3d' always draws the surface with the `front' upwards
>>> (i.e. towards higher 'z' values). This can be used to render the
>>> top and bottom differently; see 'rgl.material' and the example
>>> below."
>>>
>>> Is there a way to override this default? I have search all the
>>> related methods help and the documents on RGL's website.
>> There are lots of ways to override it: as the docs say, rgl.surface
>> is more flexible than surface3d, and you can draw triangles or quads
>> arbitrarily. What sort of thing do you want to do?
>>
>> Duncan Murdoch
>
>
> ------------------------------------------------------------------------
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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