[R] Writing my 3D plot function

Alaios alaios at yahoo.com
Mon Jun 26 08:07:49 CEST 2017


Thanks a lot for this. I never realized that my yahoo mail does not send plain text. So this is the code I have 

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))) 
} 

X1<-turnPolarToX(1,1:360) 
Y1<-turnPolarToY(1,1:360) 
Z1<-rep(0,360) 


X2<-turnPolarToX(1,1:360) 
Y2<-rep(0,360) 
Z2<-turnPolarToY(1,1:360) 

test3<-runif(360) 
X3<-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")



I hope this helps
Regards
Alex
On Monday, June 26, 2017 1:46 AM, Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote:



Please look at what I see in your code below (run-on code mush) to understand part of why it is important for you to send your email as plain text as the Posting Guide indicates.  You might find [1] helpful. 

[1] https://wiki.openstack.org/wiki/MailingListEtiquette
-- 
Sent from my phone. Please excuse my brevity.


On June 25, 2017 2:42:26 PM EDT, Alaios via R-help <r-help at r-project.org> wrote:
>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]]
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>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