[R] Writing my 3D plot function

Alaios alaios at yahoo.com
Sun Jun 25 20:42:26 CEST 2017


Hi all,I had a question last week on asking for a function that will help me draw three different circles on x,y,z axis based on polar coordinates (Each X,Y,Z circle are coming from three independent measurements of 1-360 polar coordinates). It turned out that there  is no such function in R and thus I am trying to write my own piece of code that hopefully I will be able to share. I have spent some time to write some code based on the rgl library (Still not 100% sure that this was the best option).
My input are three polar circles X,Y,Z with a good example being the image belowhttps://www.mathworks.com/help/examples/antenna/win64/xxpolarpattern_helix.png

So for X axis my input is a 2D matrix [360,2] including a single measurement per each polar coordinate. The first thing I tried was to turn my polar coordinates to cartesian ones by writing two simple functions. This works so far and I was able to print three simple circles on 3d spaceb but the problem now are the legends I need to put that remain on cartesian coordinates. As you can see from the code below all circles should have radius 1 (in terms of simplicity) but unfortunately I have the cartesian coordinates legends that do not help on reading my Figure. You can help me by executing the code below 

require("rgls")
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)))}
# Putting the first circle on 3d space. Circle of radius 1X1<-turnPolarToX(1,1:360)Y1<-turnPolarToY(1,1:360)Z1<-rep(0,360)
# Putting the second circle on 3d space. Circle of radius 1X2<-turnPolarToX(1,1:360)Y2<-rep(0,360)Z2<-turnPolarToY(1,1:360)
# Putting the third circle on 3d space. Circle of radius 1X3<-rep(0,360)Y3<-turnPolarToX(1,1:360)Z3<-turnPolarToY(1,1:360)
Min<-min(X1,Y1,Z1,X2,Y2,Z2,X3,Y3,Z3)Max<-max(X1,Y1,Z1,X2,Y2,Z2,X3,Y3,Z3)plot3d(X1,Y1,Z1,xlim=c(Min,Max),ylim=c(Min,Max),zlim=c(Min,Max),box=TRUE,axe=FALSE,add=TRUE,col="red",type="l")plot3d(X2,Y2,Z2,xlim=c(Min,Max),ylim=c(Min,Max),zlim=c(Min,Max),box=TRUE,axe=FALSE,add=TRUE,col="green",type="l")plot3d(X3,Y3,Z3,xlim=c(Min,Max),ylim=c(Min,Max),zlim=c(Min,Max),box=TRUE,axe=TRUE,add=FALSE,col="blue",type="l")
Would it be also possible to include an jpeg image file on a rgls plot?
Thanks a lotRegardsAlex
	[[alternative HTML version deleted]]



More information about the R-help mailing list