first of all before my sharing my problem I want to share a bit of code that might be helpful for some people outside there. I have been looking quite some time code to plot in 3d antenna measurements but I could not find code that does that. The problem is that antenna measurements have polar coordinates and typical 3d plot functions use cartesian coordinates. So my code below does just that (I am not an advanced programmer so I am sure someone might be able to optimize it for its use). The code can be run directly and I added comments to make it easier readable.
require("rgl") require("fields") degreeToRadian<-function(degree){ return (0.01745329252*degree) } turnPolarToX<-function(Amplitude,Coordinate){ return (Amplitude*cos(degreeToRadian(Coordinate))) } turnPolarToY<-function(Amplitude,Coordinate){ return (Amplitude*sin(degreeToRadian(Coordinate))) } # inputs for the code test<-runif(359,min=-50,max=-20) # the 359 elements correspond to the polar coordinates of 1 to 359 test2<-runif(359,min=-50,max=-20) # the 359 elements correspond to the polar coordinates of 1 to 359 test3<-runif(359,min=-50,max=-20) # the 359 elements correspond to the polar coordinates of 1 to 359 # My three input vectors above are considered to be dBm values, typically unit for antenna or propagation measurements # I want to plot those on three different 3d planes the XY, the YZ and the ZX. Since the rgl does not support # polar coordinates I need to cast my polar coordinates to cartesian ones, using the three functions # defined at the beginning. I also need to change my dBm values to their linear relative ones that are the mW # Convert my dBm to linear ones test<-10^(test/10) test2<-10^(test2/10) test3<-10^(test3/10) # Start preparing the data to be plotted in cartesian domain X1<-turnPolarToX(test,1:359) Y1<-turnPolarToY(test,1:359) Z1<-rep(0,359) X2<-turnPolarToX(test2,1:359) Y2<-rep(0,359) Z2<-turnPolarToY(test2,1:359) X3<-rep(0,359) Y3<-turnPolarToX(test3,1:359) Z3<-turnPolarToY(test3,1:359) # Time for the plotting now Min<-min(test,test2,test3) Max<-max(test,test2,test3) bgplot3d( suppressWarnings ( image.plot( legend.only=TRUE, legend.args=list(text='dBm/100kHz'), zlim=c(Min,Max),col=plotrix::color.scale(seq(Min,Max,length.out=21),c(0,1,1),c(0,1,0),0,xrange=c(Min,Max))) ) # zlim is the colorbar numbers ) # for below alternatively you can also use the lines3d to get values points3d(X1,Y1,Z1,col=plotrix::color.scale(test,c(0,1,1),c(0,1,0),0,xrange=c(Min,Max)),add=TRUE) points3d(X2,Y2,Z2,col=plotrix::color.scale(test2,c(0,1,1),c(0,1,0),0,xrange=c(Min,Max)),add=TRUE) points3d(X3,Y3,Z3,col=plotrix::color.scale(test3,c(0,1,1),c(0,1,0),0,xrange=c(Min,Max)),add=TRUE) The problem I have now is that my plotting ideally I would like to be on a log scale that the rgl packet does not support! If I try to use log on my X,Y,Z to compress them I get an error that log is not defined for negative numbers (of course that is correct). How would you think to solve that problem on compressing the axes values when log scale plotting is not supported?
I would like to thank you for your reply Regards Alex
