简体   繁体   中英

Adding a plane to a scatterplot3d

I have an equation of a line

y=sqrt(c+x^2)

and I want to add a plane to a 3d scatterplot, such that my plane is perpendicular to the xy plane and the line given above is the intersection line of the two planes.

How do I do this? I don't quite understand how plane3d works. I've read http://svitsrv25.epfl.ch/R-doc/library/scatterplot3d/html/scatterplot3d.html

But still don't get it.

This might be what you are looking for:

library(scatterplot3d)
# y=sqrt(a+x^2) with x in (-0.5,0.5), z in (0,1) and a=0
a <- 0
x <- rep(seq(-0.5, 0.5, length = 200), each = 200)
y <- sqrt(a + x^2)
z <- rep(seq(0, 1, length = 200), 200)
scatterplot3d(x, y, z, highlight.3d = TRUE, pch = 20)

在此处输入图片说明

Edit: That would be helpful to see how did you add these other points, but let us take the second example from ?scatterplot3d

  temp <- seq(-pi, 0, length = 50)
  x2 <- c(rep(1, 50) %*% t(cos(temp)))
  y2 <- c(cos(temp) %*% t(sin(temp)))
  z2 <- c(sin(temp) %*% t(sin(temp)))

Now combining x with x2 and doing the same with others we get:

scatterplot3d(c(x,x2), c(y,y2), c(z,z2), highlight.3d = TRUE, pch = 20)

在此处输入图片说明

In addition to the previous answer, once you construct a 3-D scatterplot, you can add a plane to it by creating a model and parsing it using a function nested within your scatterplot3d() container. It should look something like this:

plot3d <- scatterplot3d(x, y, z, ... )
model  <- lm(y ~ sqrt(c + x^2) + z)
plot3d$plane3d(model)

It's a very weird syntax to have a function within a container like that, but it works, giving you something like this (the dotted-line plane is visible near the center of the cube):

平面穿过中心的3-D散点图

If you would like to create one or multiple planes manually, I would use Uwe's method that I re-posted here :

spd <- scatterplot3d(1:10, 1:10, 1:10)

# xy
spd$plane3d(0.3549896,0,0,lty="dotted")

# yz
x0 <- 5
xyz1 <- spd$xyz.convert(rep(x0, 6), rep(0, 6), seq(0, 10, by=2))
xyz2 <- spd$xyz.convert(rep(x0, 6), rep(10, 6), seq(0, 10, by=2))
segments(xyz1$x, xyz1$y, xyz2$x, xyz2$y, lty="dotted")

xyz1 <- spd$xyz.convert(rep(x0, 6), seq(0, 10, by=2), rep(0, 6))
xyz2 <- spd$xyz.convert(rep(x0, 6), seq(0, 10, by=2), rep(10, 6))
segments(xyz1$x, xyz1$y, xyz2$x, xyz2$y, lty="dotted")

# zx
y0 <- 6
xyz1 <- spd$xyz.convert(rep(0, 6), rep(y0, 6), seq(0, 10, by=2))
xyz2 <- spd$xyz.convert(rep(10, 6), rep(y0, 6), seq(0, 10, by=2))
segments(xyz1$x, xyz1$y, xyz2$x, xyz2$y, lty="dotted")

xyz1 <- spd$xyz.convert(seq(0, 10, by=2), rep(y0, 6), rep(0, 6))
xyz2 <- spd$xyz.convert(seq(0, 10, by=2), rep(y0, 6), rep(10, 6))
segments(xyz1$x, xyz1$y, xyz2$x, xyz2$y, lty="dotted")

This produces planes through manual specification:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM