在 plotly 中从 x+y+z=6 方程绘制 3d 平面
Plot 3d plane from x+y+z=6 equation in plotly
我有一组方程式 (z1) x+y+z=6, (z2) x+2y+2z=9 和 (z3) x+3y+4z=13 并且想绘制平面使用 plotly.
方法一:使用mesh3d
require(plotly)
x<-seq(from=-10, to=10, by=1)
y<-seq(from=-10, to=10, by=1)
z1<-6-x-y #For the first plane
fig <- plot_ly(x = ~, y = ~y, z = ~z1, type = 'mesh3d')
fig
虽然没有产生输出。为什么?
方法二:利用曲面
虽然这产生了一个平面但是错误的。
library(plotly)
x<-seq(from=-10,to=10,by=1)
y<-seq(from=-10,to=10,by=1)
z1<-6-x-y
z1<-matrix(rep(z1,10),NROW(x),10)
fig <- plot_ly(showscale = FALSE)
fig <- fig %>% add_surface(z = ~z1)
fig
这个平面不正确。如果您查看点 x=2、y=2,z 应该等于 2,但事实并非如此。相反,它是 22,这是不正确的。
当x <- seq(from=-10, to=10, by=1); y<-seq(from=-10, to=10, by=1)
时,x+y+z=6不是平面而是直线
您需要准备更多的数据点。
library(dplyr); library(tidyr); library(plotly)
x <- seq(from=-10, to=10, by=1)
y <- seq(from=-10, to=10, by=1)
z1 <- 6-x-y #For the first plane
origin <- tibble(x = x, y = y, z = z1)
# prepare all combination of x and y, and calculate z1
xyz1 <- tidyr::crossing(x, y) %>%
mutate(z1 = 6-x-y)
plot_ly(x = ~x, y = ~y, z = ~z1, type = "mesh3d", data = xyz1) %>%
add_markers(~ x, ~y, ~z1, data = origin)
橙色点是你准备的数据(当x <- seq(from=-10, to=10, by=1); y<-seq(from=-10, to=10, by=1)
时,x+y+z=6是直线。)
我有一组方程式 (z1) x+y+z=6, (z2) x+2y+2z=9 和 (z3) x+3y+4z=13 并且想绘制平面使用 plotly.
方法一:使用mesh3d
require(plotly)
x<-seq(from=-10, to=10, by=1)
y<-seq(from=-10, to=10, by=1)
z1<-6-x-y #For the first plane
fig <- plot_ly(x = ~, y = ~y, z = ~z1, type = 'mesh3d')
fig
虽然没有产生输出。为什么?
方法二:利用曲面
虽然这产生了一个平面但是错误的。
library(plotly)
x<-seq(from=-10,to=10,by=1)
y<-seq(from=-10,to=10,by=1)
z1<-6-x-y
z1<-matrix(rep(z1,10),NROW(x),10)
fig <- plot_ly(showscale = FALSE)
fig <- fig %>% add_surface(z = ~z1)
fig
这个平面不正确。如果您查看点 x=2、y=2,z 应该等于 2,但事实并非如此。相反,它是 22,这是不正确的。
当x <- seq(from=-10, to=10, by=1); y<-seq(from=-10, to=10, by=1)
时,x+y+z=6不是平面而是直线
您需要准备更多的数据点。
library(dplyr); library(tidyr); library(plotly)
x <- seq(from=-10, to=10, by=1)
y <- seq(from=-10, to=10, by=1)
z1 <- 6-x-y #For the first plane
origin <- tibble(x = x, y = y, z = z1)
# prepare all combination of x and y, and calculate z1
xyz1 <- tidyr::crossing(x, y) %>%
mutate(z1 = 6-x-y)
plot_ly(x = ~x, y = ~y, z = ~z1, type = "mesh3d", data = xyz1) %>%
add_markers(~ x, ~y, ~z1, data = origin)
橙色点是你准备的数据(当x <- seq(from=-10, to=10, by=1); y<-seq(from=-10, to=10, by=1)
时,x+y+z=6是直线。)