On 23/06/2016 5:59 AM, Nicole Karakin wrote:
I am trying to follow help and Internet examples to create a very
simple animation of a 3d-line in R. This is just a test and my final
goal is to use this functionality to visually verify results of some
geometrical transformations on 3d-movement data that I am analysing.
So basically I need nothing more than a ‘3d-player’ interface that
allows for usual interaction (rotation, zoom, play, stop, slide).

I figured out that rgl package does the job and I am able to use it
for the sphere/points animation. But now I need to use it on lines and
I get very strange results. In the example below there are 4 points
and two lines (cyan and red) that connect the same points but the red
line is for some reason in the ‘wrong’ place. The animation doesn’t
make sense neither. Now, I am thinking may be it is impossible to do
>> to animate more than one vertex with more than one attribute? But I
don’t see this in documentation and obviously it is possible because
line is animated! I spent quite a long time trying to figure out what
is going on and will appreciate any help/advise/directions on how i
can 'fix' this behaviour.
thanks, Nicole

Ps: the code below is a chunk in the markdown file and I am using Rstudio

#-----------------------------------------
require(rgl)
require(rglwidget)
p11=c(0,0,0)
p21=c(50,50,0)
p12=c(50,0,0)
p22=c(10,50,50)

saveopts <- options(rgl.useNULL = TRUE)
did=list()
did[[1]]=plot3d(rbind(p11,p21,p12,p22), type="s", alpha = 1, lwd = 5,
col = c('brown','darkgreen','orange','green'))
did[[2]]=spheres3d(c(100,100,100), alpha = 1, lwd = 5, col = "blue",radius=2)
did[[3]]=lines3d(rbind(p11,p21),lwd=8, col='cyan',alpha=.9)
did[[4]]=planes3d(0, 0, 1, 0, alpha=.4, col='green')
did[[5]]=lines3d(rbind(p11,p21),lwd=2, col='red')
aspect3d(1, 1, 1)
did[[6]]=grid3d(c("x-", "z-"),at = NULL,col = "gray",lwd = .5,lty = 1,n = 5)
sceneT = rglwidget(elementId = "plot3dT",width=500, height=300) #%>%
rgl.ids()
rgl.attrib(id=did[[3]],attrib = c(1:length(did[[3]])))

playwidget(sceneT,list(
   vertexControl(values = rbind(c(0,0,0,0,0,0),c(50,50,50,50,50,50)),
              vertices = 1:6, attributes = "z", objid = did[[4]], param
= 1:2,interp =T),
   vertexControl(values = r1,
              vertices = 1:2, attributes = c('x',"y","z",'x',"y","z"),
objid = did[[5]], param = 1:2,interp =T)),
   start = 1, stop = 2, step = .1, precision = 3)
options(saveopts)

You can run rglwidget-using scripts in RStudio (or other front ends) and they'll generally work more or less the same as they do in a Markdown document. However, when I try to do that with this one, it fails, because you use r1 without defining it. You might want to think about deleting everything unnecessary as well: if you want to illustrate problems with lines, just show lines.

You should also say what versions of rgl and rglwidget you're using; the ones on R-forge are quite a bit newer than the ones on CRAN.

Duncan Murdoch

______________________________________________
R-help@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.

Reply via email to