# Create a labeller to show the coordinates of the selected point.
labelLocation <- function(x, y = NULL, z = NULL) {
xyz <- xyz.coords(x, y, z)
function(sel, ...) {
p <- with(xyz, matrix(c(x[sel], y[sel], z[sel]), ncol = 3))
c(text3d(p, texts = sprintf("x:%.2f", p[1]),
adj = c(-0.2, -0.6), ...),
text3d(p, texts = sprintf("y:%.2f", p[2]),
adj = c(-0.2, 0.5), ...),
text3d(p, texts = sprintf("z:%.2f", p[3]),
adj = c(-0.2, 1.6), ...))
}
}
xyz <- matrix(rnorm(30), ncol = 3)
open3d()
ids <- plot3d(xyz)
hover3d(xyz, labeller = labelLocation(xyz), col = "red", cex = 0.8)
# The same thing using the data id:
# hover3d(ids["data"],
# labeller = labelLocation(rgl.attrib(ids["data"], "vertices")),
# col = "red", cex = 0.8)
Run the code above in your browser using DataLab