制作时间序列的 3D 渲染图

发布于 2024-12-16 13:41:41 字数 1095 浏览 1 评论 0原文

我有一组 3D 坐标(下面 - 仅针对 3D 空间中的单个点):

x <- c(-521.531433, -521.511658, -521.515259, -521.518127, -521.563416, -521.558044, -521.571228, -521.607178, -521.631165, -521.659973)
y <- c(154.499557, 154.479568, 154.438705, 154.398682, 154.580688, 154.365189, 154.3564, 154.559189, 154.341309, 154.344223)
z <- c(864.379272, 864.354675, 864.365479, 864.363831, 864.495667, 864.35498, 864.358582, 864.50415, 864.35553, 864.359863)
xyz <- data.frame(x,y,z)

我需要使用 3D 渲染绘制该点的时间序列图(以便我可以旋转图等)。该图将可视化上述点在时间上的轨迹(例如以实线的形式)。我使用了 'rgl' 包plot3d 方法,但我无法绘制时间序列(下面,仅从时间序列的第一帧绘制一个点):

require(rgl)    
plot3d(xyz[1,1],xyz[1,2],xyz[1,3],axes=F,xlab="",ylab="",zlab="") 

我发现 这篇文章,但它并没有真正处理实时渲染的 3D 绘图。我将不胜感激任何建议。谢谢。

I have a set of 3D coordinates (below - just for a single point, in 3D space):

x <- c(-521.531433, -521.511658, -521.515259, -521.518127, -521.563416, -521.558044, -521.571228, -521.607178, -521.631165, -521.659973)
y <- c(154.499557, 154.479568, 154.438705, 154.398682, 154.580688, 154.365189, 154.3564, 154.559189, 154.341309, 154.344223)
z <- c(864.379272, 864.354675, 864.365479, 864.363831, 864.495667, 864.35498, 864.358582, 864.50415, 864.35553, 864.359863)
xyz <- data.frame(x,y,z)

I need to make a time-series plot of this point with a 3D rendering (so I can rotate the plot, etc.). The plot will visualize a trajectory of the point above in time (for example in the form of solid line). I used 'rgl' package with plot3d method, but I can't make it to plot time-series (below, just plot a single point from first frame in time-series):

require(rgl)    
plot3d(xyz[1,1],xyz[1,2],xyz[1,3],axes=F,xlab="",ylab="",zlab="") 

I found this post, but it doesn't really deal with a real-time rendered 3D plots. I would appreciate any suggestions. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

很酷又爱笑 2024-12-23 13:41:41

如果您阅读 help(plot3d) 您可以了解如何绘制线条:

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

这是您想要的吗?

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?

南冥有猫 2024-12-23 13:41:41

这个怎么样?它使用 rgl.pop() 删除点和线并将它们绘制为轨迹 - 更改 sleep 参数来控制速度:

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

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,])
  }
}
行至春深 2024-12-23 13:41:41

解决方案比我想象的要简单,问题是我没有在数据上使用 as.matrix 。当我只是尝试使用 plot3d 绘制整个数据集时,我收到错误 (list) object Cannot be coerced to type 'double' (找到了此问题的解决方案 此处)。因此,如果您需要绘制坐标集的时间序列(在我的例子中是两个演员的运动捕捉数据),这是我的完整解决方案(仅适用于下面的数据集!):

  • 下载示例数据集
  • 将上述数据读入表格:

    data <- read.table("Bob12.txt",sep="\t")
    
  • 将 XYZ 坐标提取到单独的矩阵中:

    x <- as.matrix(subset(data,select=seq(1,88,3)))
    y <- as.matrix(子集(数据,select=seq(2,89,3)))
    z <- as.matrix(子集(数据,select=seq(3,90,3)))
    
  • 使用 'rgl' 包

    <前><代码>要求(rgl)
    plot3d(x[1:nrow(x),],y[1:nrow(y),],z[1:nrow(z),],axes=F,xlab="",ylab="",zlab =“”)

您应该得到如下图所示的内容(但您可以旋转它等) - 希望您能认识到那里有为人们提供的联合中心。我仍然需要调整它以使其在视觉上更好 - 将第一帧作为点(以清楚地看到演员的关节),然后是可见的中断,然后其余帧作为线。

根据上述数据输出上述代码

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.

Output of the above code from the above data

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文