[R] RGL 'front' upwards default in rendering image
Joe Byers
joe-byers at utulsa.edu
Tue Oct 3 17:31:19 CEST 2006
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.
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
res<- rotationMatrix(pi,0, 1, 0) # attempt to set rotation, does not
make a difference
#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);
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
More information about the R-help
mailing list