比如我喜欢演示3d曲面
z = sin(sqrt(x^2 + y^2))/sqrt(x^2 + y^2)
和曲率x*y = 10
.
我可以用下面的代码做表面,但我知道如何添加曲率。
# Load the required packages
library(plotly)
# Generate data for the x, y, and z coordinates
x <- seq(-10, 10, length.out = 50)
y <- seq(-10, 10, length.out = 50)
z <- outer(x, y, function(x, y) {sin(sqrt(x^2 + y^2))/sqrt(x^2 + y^2)})
# Create a 3D surface plot
surface <- plot_ly(x = x, y = y, z = z, type = "surface")
不一定是
plotly
,欢迎任何其他建议。
谢谢。
关于曲率,这是否意味着您要显示另一个对应于 x*y 的结果矩阵?
如果是这样,下面的代码是否回答了你的问题?
### Import libraries
library(plotly)
### Pre-processing
# Generate data for the x, y, and z coordinates
x <- seq(-10, 10, length.out = 50)
y <- seq(-10, 10, length.out = 50)
z <- outer(x, y, function(x, y) {sin(sqrt(x^2 + y^2))/sqrt(x^2 + y^2)})
# Generate a second matrix of results
z2 <- outer(x, y, function(x, y) {(x*y)})
### Display plot
# Create a 3D surface plot
surface <- plot_ly(x = x, y = y, z = z, type = "surface")
# Add another layer
surface %>% add_surface(z = ~z2, opacity = 0.98)