I am trying to plot the plane determined by the equation y = x between 0 and 2 superimposed on a 3D surface described by z = 1/2 * x * y.
I "hacked" code from another question to get a minimally satisfactory representation of the surface (wouldn't mind a fresh start on that), but I have no idea how to superimposed the 2D plane.
Here is the idea:
And this is what I got so far:
with the borrow code:
my_surface <- function(f, n=10, ...) {
ranges <- rgl:::.getRanges()
x <- seq(ranges$xlim[1], ranges$xlim[2], length=n)
y <- seq(ranges$ylim[1], ranges$ylim[2], length=n)
z <- outer(x,y,f)
surface3d(x, y, z, ...)
}
library(rgl)
f <- function(x, y) 1/2 * x * y
g <- function(x, y) x = y
x <- seq(0, 2, by=0.001)
y <- seq(0,2, by=0.001)
z <- 1/2 * x * y
plot3d(x, y, z, xlab="X", ylab="y", zlab="z", site=5, type = "n")
my_surface(f, alpha=.5, col="red")
my_second_surface <- function(f, n=10, ...) {
ranges <- rgl:::.getRanges()
x <- seq(ranges$xlim[1], ranges$xlim[2], length=n)
y <- seq(ranges$ylim[1], ranges$ylim[2], length=n)
z <- outer(x,y,g)
surface3d(x, y, z, ...)
}
my_second_surface(g, alpha=.5, col="blue")
Notice that the main problem (or difference with the sketch on the first graph) is that I can't make the greenish triangle appear. Instead, I get an oblique plane in blue.