I'm creating surfaces in 3D and then adding noise to the points defining
the surface. I'd like to plot the surface, along with points (using
perspp) showing noisy values as points on a perspective plot of the
surface. I've created a data frame containing all the x, y and z values.
I also create a matrix with the smooth z-values and plot it with
persp(). syn.df contains the synthesized surface with all the x, y, and
z values, one triplet on each row, and syn.mat contains all the z
values in a matrix. syn.pts contains the x values ranging from -5 to 5
incremented by 1. I thought this would do it:
synmat.fun <- function(x, y, dzdx = 1.5, dzdy = 2.5){
z <- 4 - dzdx * x^2 - dzdy * y^2
return(z)
}
syn.df <- data.frame(x= rep(-5:5, each = 11), y = rep(-5:5, 11), z =
rep(NA, 121))
syn.df$z <- synmat.fun(syn.df$x, syn.df$y
syn.pts <- seq(from = -5, to = 5)
syn.mat <- outer(syn.pts, syn.pts, synmat.fun)
info.p <- persp(x = syn.pts, y = syn.pts, syn.mat)
perspp(syn.df$x, syn.df$y, syn.df$z + rnorm(length(syn.df$z), info.p)
Everything works fine, yet the perspp() function never plots the points
for me: nothing happens when I call it except that I see two elements of
a list, x, and y, that show the 2D x and y projected locations of the
points to be plotted, but no points appear. I've done nothing strange
with par() so I'm not sure what to try next.
Kim Elmore
|