1

I'm trying to plot the position of an object in 3D space (x, y, and z co-ordinates) over time so that I can determine the path of the object.

I'm finding it hard to visualise how this would work. I can plot the (x,y,z) coordinates in a 3D space, but how to visualize the progress of time?

I am using R, and I have attached below the results of scatterplot3d() function in R.

Could you please guide me how to visualize the dataset. Also, it would help me if you could suggest any other tools for this type of visualization.

[image] https://www.dropbox.com/s/6douprzlllfhd3c/Screenshot%202014-11-10%2019.14.19.png?dl=0

[sample data set]

Time    X   Y   Z

1   245.00  198.00  247.00
2   247.00  197.50  246.50
3   249.00  198.20  245.20
5   250.25  200.50  243.75
6   249.20  202.80  242.40
7   251.00  201.75  241.50
8   249.40  199.20  241.80
9   252.80  196.20  242.20
10  256.60  200.80  242.20
Calvin
  • 13
  • 1
  • 3

2 Answers2

4

For an interactive, browser-based animation, check out the animation package:

library(animation)
df<-matrix(rnorm(90),ncol=3)
saveHTML({
    for (i in 1:nrow(df)) {
    pt<-df[i,]
    scatterplot3d(pt[1],pt[2],pt[3],
    xlim=c(-4,4),ylim=c(-4,4),zlim=c(-4,4)
      )}
})

EDIT: include library call


Or this, which uses OP's data and plots the evolving path.

library(animation)
library(scatterplot3d)
saveHTML({
  for (i in 2:nrow(df)) {
    with(df[1:i,],scatterplot3d(X,Y,Z,type="l",
         xlim=range(df$X),ylim=range(df$Y),zlim=range(df$Z)))
    }
})
jlhoward
  • 58,004
  • 7
  • 97
  • 140
keegan
  • 2,892
  • 1
  • 17
  • 20
  • I was able to animate the data set. Thanks for the help. I was wondering if there is a way to add 'trails' to indicate the movement from 'previous' location to 'next' location. This will help me visualize the entire trajectory covered by the object, during its lifetime. – Calvin Nov 10 '14 at 19:27
  • Looks like it is working fine with my data. Though the final output wasn't quite interesting, but the plotting is correct as far as I can tell. Sadly, I could not add curves/lines to show the path of the data points over time. Could you help with it? [image] https://www.dropbox.com/s/qp0cr5nzpmqavt7/Screenshot%202014-11-10%2022.12.39.png?dl=0 I would like to have something like this https://www.dropbox.com/s/osf391h0xf5ab3m/sample.png?dl=0 – Calvin Nov 10 '14 at 20:15
  • The second code snippet draws lines from point to point, indicating the path. If you want a curved path, you would need to know what function to use to interpolate between the points. This is basically linear interpolation. – jlhoward Nov 10 '14 at 22:28
2

Expanding on the comment (calling your sample df).

library(rgl)
with(df,lines3d(X,Y,Z))
with(df[1,],points3d(X,Y,Z,size=7,col="red"))
with(df[-1,],points3d(X,Y,Z,col="blue"))
axes3d()
title3d(xlab="X",ylab="Y",zlab="Z")

This code produces a rotatable 3D plot of your data. Below is a screen shot. The red dot is the starting point.

jlhoward
  • 58,004
  • 7
  • 97
  • 140