Make a 3D rendered plot of time-series

不想你离开。 提交于 2019-12-07 04:00:28
Spacedman

How about this? It uses rgl.pop() to remove a point and a line and draw them as a trail - change the sleep argument to control the speed:

ts <- function(xyz,sleep=0.3){
  plot3d(xyz,type="n")
  n = nrow(xyz)
  p = points3d(xyz[1,])
  l = lines3d(xyz[1,])
  for(i in 2:n){
    Sys.sleep(sleep)
    rgl.pop("shapes",p)
    rgl.pop("shapes",l)
    p=points3d(xyz[i,])
    l=lines3d(xyz[1:i,])
  }
}
Spacedman

If you read help(plot3d) you can see how to draw lines:

require(rgl)    
plot3d(xyz$x,xyz$y,xyz$z,type="l")

Is that what you want?

Geek On Acid

The solution was simpler than I thought and the problem was that I didn't use as.matrix on my data. I was getting error (list) object cannot be coerced to type 'double' when I was simply trying to plot my entire dataset using plot3d (found a solution for this here). So, if you need to plot time-series of set of coordinates (in my case motion capture data of two actors) here is my complete solution (only works with the data set below!):

  • download example data set
  • read the above data into a table:

    data <- read.table("Bob12.txt",sep="\t")
    
  • extract XYZ coordinates into a separate matrixes:

    x <- as.matrix(subset(data,select=seq(1,88,3)))
    y <- as.matrix(subset(data,select=seq(2,89,3)))
    z <- as.matrix(subset(data,select=seq(3,90,3)))
    
  • plot the coordinates on a nice, 3D rendered plot using 'rgl' package:

    require(rgl)
    plot3d(x[1:nrow(x),],y[1:nrow(y),],z[1:nrow(z),],axes=F,xlab="",ylab="",zlab="")
    

You should get something like on the image below (but you can rotate it etc.) - hope you can recognise there are joint centers for people there. I still need to tweak it to make it visually better - to have first frame as a points (to clearly see actor's joints), then a visible break, and then the rest of frames as a lines.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!