How to create 2D slice plots from 3D data in R ?

998 Views Asked by At

Here is the R code for my 3d Plot... I want to generate 2d slices of this 3d plot. I am using package rgl in R.

   library(rgl)

    > ncv1
             [,1]          [,2]          [,3]
[1,] 0.0087173253  0.0015347787  0.0007591226
[2,] 0.0015347787  0.0066770936 -0.0001649119
[3,] 0.0007591226 -0.0001649119  0.0011324989

> ncv2
             [,1]          [,2]          [,3]
[1,] 0.0080515223  0.0012391863  0.0006745652
[2,] 0.0012391863  0.0064364687 -0.0001695962
[3,] 0.0006745652 -0.0001695962  0.0011687981

> ntruemean
[1] 4.775067 5.596896 1.142223

> open3d()
wgl 
 10 

plot3d(ellipse3d(ncv2,ntruemean),col="red",type='shade',xlim=c(-2,2),ylim=c(-2,2),zlim=c(-2,2))

plot3d(ellipse3d(ncv1,ntruemean),col="blue",type='wire',add=TRUE,xlim=c(-2,2),ylim=c(-2,2),zlim=c(-2,2))

rgl.postscript("persp3dd1.eps","eps")

enter image description here

1

There are 1 best solutions below

2
On

You can slice it pretty easily in any plane you like. You just need to figure out the coefficients of the equation of the plane in a x + b y + c z + d = 0 format, which is a 1st year linear algebra problem.

I can't do that for you, because I don't know what ellipse you are intending to draw, or what you mean by "right in the center". You use ntruemean as a variable name, but pass it as the scale parameter, which doesn't really make sense. I suspect you meant to pass it as the centre parameter.

Assuming that's what you meant, this clips in the center:

library(rgl)
ncv2 <- diag(1:3) # not your values
ntruemean <- 4:6  # also not your values
plot3d(ellipse3d(ncv2, centre = ntruemean),
       col="red", type='shade')
plot3d(ellipse3d(ncv2*1.01, centre = ntruemean), col = "blue", type="wire", add = TRUE)
normal <- 7:9  # Choose your own normal!
clipplanes3d(normal, d = -sum(normal * ntruemean))