Objective

This program displays a 3D plot of two linked donuts using plotly

Definition of functions for the two donuts

donut<-function(mradius,radius){
  omega=1
  n=150
  #omega in deg/sec
  #mraidus is the minor radius
  #radius is the major radius
  time<-seq(from=0,to=360/omega,by=1/10)
     pi<-3.141592653
   z<-mradius*(sin(n*omega*pi/180*time))
     rxy<-mradius*(cos(n*omega*pi/180*time))+radius
     x<-rxy*cos(omega*pi/180*time)
     y<-rxy*sin(omega*pi/180*time)+radius
     result<-data.frame(x=x,y=y,z=z)
  return(result)
}
loop<-function(mradius,radius){
  omega=1
  n=150
  #omega in deg/sec
  #mraidus is the minor radius
  #radius is the major radius
  time<-seq(from=0,to=360/omega,by=1/10)
  pi<-3.141592653
   x<-mradius*(sin(n*omega*pi/180*time))
   rxy<-mradius*(cos(n*omega*pi/180*time))+radius
   y<-rxy*cos(omega*pi/180*time)
   z<-rxy*sin(omega*pi/180*time)
   result<-data.frame(x=x,y=y,z=z)
   return(result)
}

Compute dataframes of donuts with dimensions defined and Plot them

d1<-donut(5,15)
pltr<-cbind(name="Donut1",d1)

#minor radius=5, major radius=15 for both donuts
################
d2<-loop(5,15)
#readline("p")
pltl<-cbind(name="Donut2",d2)
plt<-rbind(pltr,pltl)

plt$name<-as.factor(plt$name)

###############
plot_ly(x=plt$x,y=plt$y,z=plt$z,type="scatter3d",mode="marker",sizes=2,color=plt$name)
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels

## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels