-1

I have a dataset that contains 13 cameras, each camera location was reconstructed 5 times. I have aggregated the measurements into a mean and standard deviation for each the 6 variables that relate to the position of the camera [X, Y, Z, Omega, Phi, Kappa]. I would like to plot the positions of the cameras based on the XYZ mean values but then create an ellipsoid for each location based on the standard deviation values for each of the XYZ values. (like an error bar, which would also be acceptable but my first goal is to create colorized ellipsoids showing the directions of greatest variance or error... for this example I am using the standard deviation value.)

I am using rgl to plot the mean position of each camera but I am not sure how to change the shape of each plotted point by the values from another vector or column.

The position data is aggregated to the mean values here

pos.mean

PhotoID           X           Y        Z
DSC_7120 -269.697307 -359.608029 2390.520
DSC_7121 -323.537075 -312.080524 2388.374
DSC_7122 -381.084880 -259.807930 2386.175
DSC_7123 -434.500687 -212.438305 2384.080
DSC_7707 -297.275547  -12.954589 2352.626
DSC_7708 -238.105775  -61.327624 2353.830
DSC_7709 -178.910977 -110.464992 2354.912
DSC_7710 -124.471751 -155.745775 2356.300
DSC_7711  -65.107734 -205.164167 2358.239
DSC_7794   -2.828331    9.167357 2308.687
DSC_7795  -61.841640   56.621020 2307.068
DSC_7796 -118.768896  104.237722 2306.107
DSC_7797 -176.829418  150.560971 2304.887

and the standard deviation values are:

pos.sd

PhotoID         X         Y            Z
DSC_7120 0.1507733 0.3651178 0.0018517456
DSC_7121 0.1508845 0.3633876 0.0005815413
DSC_7122 0.1512489 0.3671259 0.0021316858
DSC_7123 0.1498382 0.3667440 0.0050629647
DSC_7707 0.1495099 0.3600409 0.0016483624
DSC_7708 0.1470677 0.3583582 0.0014911045
DSC_7709 0.1458569 0.3596208 0.0021194229
DSC_7710 0.1396953 0.3604535 0.0033336396
DSC_7711 0.1414401 0.3620422 0.0047287867
DSC_7794 0.1442061 0.3691425 0.0056096078
DSC_7795 0.1516369 0.3688717 0.0016928413
DSC_7796 0.1565440 0.3672701 0.0038089509
DSC_7797 0.1547617 0.3726132 0.0079183205

The basic 3D plot currently can be viewed as such

library(rgl)
with(smry.mean, 
     plot3d(X, Y, Z,
            type="s"))

Is there a way to change the points into colorized ellipsoids where the dimensions and color of the ellipsoids is built from the standard deviation values for each point?

Thank you

c0ba1t
  • 241
  • 2
  • 15

1 Answers1

0

You can do it using the ellipse3d function, but you'll have to draw the ellipsoids one at a time. For example,

for (id in pos.mean$PhotoID) 
  ellipse3d(diag(pos.sd[id, c("X", "Y", "Z")])^2, centre = pos.mean[id, c("X", "Y", "Z")], col = "red", t = 10)

You'll want to play around with that t parameter to set the scale appropriately: your SD values are pretty small compared to the range of the means, so t = 10 might just give invisibly small ellipsoids. If so, try a bigger value.

One other thing: if you only know SD values, you won't get "the directions of greatest variance or error". That likely needs a full covariance matrix, not the diagonal one I constructed.

user2554330
  • 37,248
  • 4
  • 43
  • 90
  • conceptually this makes sense, I appreciate the response. I am getting an error using this approach `Error: is.matrix(x) is not TRUE` - Also, I think there may be a way to plot all of them in 3D simultaneously using the `cda` package but I don't know if I can combine them both. I am working on that now, I will keep the question updated. link to potential solution here https://stackoverflow.com/a/26758171/2073255 – c0ba1t Jul 18 '17 at 09:47
  • For a single ellipse this works... `foo <- diag(c(pos.sd[1,2], pos.sd[1,3], pos.sd[1,4])) plot3d(ellipse3d(foo, center = c(0,0,0)))` – c0ba1t Jul 18 '17 at 10:00
  • `for (id in rownames(df.mean)) { plot3d( ellipse3d( diag(df.sd[id, c("X", "Y", "Z")]), center = df.mean[id, c("X", "Y", "Z")], col = "red", t = 10)) }` – c0ba1t Jul 18 '17 at 10:18
  • This is one reason you should post a reproducible example -- then people could test their answers. The second line of my code should be ` ellipse3d(diag(pos.sd[id, c("X", "Y", "Z")])^2, centre = pos.mean[id, c("X", "Y", "Z")], col = "red", t = 10)`. I've changed it to that. – user2554330 Jul 18 '17 at 22:11
  • The example should be reproducible, either way, your answer is appreciated but still doesn't answer the question. One at a time isn't what I need. Thanks again, I will post and answer when I figure it out. If anyone else has suggestions I would appreciate them a great deal! Cheers. – c0ba1t Jul 18 '17 at 22:36
  • Your code certainly isn't reproducible. Try running it in a clean session. – user2554330 Jul 19 '17 at 00:06
  • "I will update the question with reproducible code. – c0ba1t 2 days ago". Really? – user2554330 Jul 21 '17 at 16:42
  • Lol. Yeah, traveling in Europe for work. Won't be on computer for a few more days. Thanks for checking in ;) – c0ba1t Jul 21 '17 at 16:43