library(rgl) ## Define the quadratic form A <- 2; B <- 1; C <- 2 Q <- function(x1,x2){ A*x1^2+2*B*x1*x2+C*x2^2 } ## Define the density D <- A*C-B^2; f <- function(x1,x2) {sqrt(D)/(2*pi)*exp(-Q(x1,x2)/2)} ## Prepare 3D plot data x1 <- seq(-2,2,.1); x2 <- seq(-2,2,.1); z <- outer(x1,x2,f) ## Plot the density open3d() ncolors <- 20 col <- terrain.colors(ncolors) persp3d(x=x1,y=x2,z=z,theta=20,phi=50,col=col)