[R] movie3d function in the rgl package

Duncan Murdoch murdoch at stats.uwo.ca
Sat Oct 25 01:11:18 CEST 2008


On 24/10/2008 1:55 PM, Dani wrote:
> Dear list,
> 
> I'm using the function "movie3d" in the package "rgl" to create a .gif
> animation of a 3d graphic.  The program "ImageMagik" is working
> properly, R packages are working, basic examples available in the
> manual also working fine.
> 
> Problem Solved: when I tried to create more complex movies, i.e.
> combining different views and zooming, the R-console crashed or
> returned error playing the function returned by par3dinterp, using
> heterogeneous parameters. When not crashing, "Error:
> length(userMatrix) == 16 * length(times) is not TRUE."

I'm glad you solved your problem.  Just one comment on your solution:

> Counterexample:
> #rotating
> v=seq(from=1,to=61,by=2.5)
> for (i in 1:length(v)){
>   rgl.viewpoint(270+v[i],80-(v[i]/1))     #This is a counterexample

It's always a bad idea to mix rgl.* functions with *3d functions.  In 
this case you might get away with it, but you'd be better off using 
view3d().

Duncan Murdoch

>   M <- par3d()
>   lista[[k]]=M;
>   k=k+1;
> }
> #zooming
> v=seq(from=1,to=0.12,by=-0.02)
> for (i in 1:length(v)){
>  par3d(zoom=v[i])
>  M <- par3d()
>  lista[[k]]=M; k=k+1;
> }
> #-------------- Ending view
> rgl.viewpoint(326,40)
> par3d(zoom=1)
> M <- par3d()
> lista[[k]]=M; k=k+1;
> 
> p = par3dinterp(lista)
> play3d(p) # or movie3d (p,12)
> ----------------------------------------------------------------------
> Light: after 2 weeks fighting with the function + a bag of coffee, I
> found this function really helpful and I WANTED TO SHARE since I
> didn't find anything like that in the web.
> Step 1: set the zooming parameters to each view you want in a separate
> vector (list_zooming) while accumulating the views in the
> list_userMatrix
> #rotating
> v=seq(from=1,to=61,by=30)#2.5)
> for (i in 1:length(v))
> {
>   rgl.viewpoint(270+v[i],80-(v[i]/1))
>   M <- par3d("userMatrix")            #This is an example who runs perfectly
>   list_userMatrix[[k]]=M;
>   k=k+1;
> }
> list_z=rep(1,length(v)); list_zooming=c(list_zooming,list_z)
> 
> #zooming
> v=c(1,0.12)#seq(from=1,to=0.12,by=-0.2)
> for (i in 1:length(v))
> {
>  list_zooming=c(list_zooming,v[i])
>  M <- par3d("userMatrix")
>  list_userMatrix[[k]]=M; k=k+1;
> }
> #--------------
> rgl.viewpoint(345,30)
> par3d(zoom=0.1)
> M <- par3d("userMatrix")
> list_userMatrix[[k]]=M; k=k+1;
> 
> p = par3dinterp( userMatrix=list_userMatrix,zoom=list_zooming)
> 
> movie3d (p,duration=12)#as.integer(length(list_userMatrix)))
> #play3d(p)
> 
> Hope it was helpful! Good lucky!
> --
> -------------------------------------
> Daniela
> 
> ______________________________________________
> R-help at r-project.org mailing list
> 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