如何在Rgl plot3d中绘制表面

时间:2018-11-20 17:10:49

标签: r rgl

所以我有这段代码可以产生精确的表面

f = function(x, y){
    z = ((x^2)+(3*y^2))*exp(-(x^2)-(y^2))
}
plot3d(f, col = colorRampPalette(c("blue", "white")), 
       xlab = "X", ylab = "Y", zlab = "Z", 
       xlim = c(-3, 3), ylim = c(-3, 3),
       aspect = c(1, 1, 0.5))

给出以下图解: 3d exact plot 现在,我有一些代码可以执行随机步行都会算法来重现以上图像。我认为它的工作方式就像我对这些计算值进行了另一次绘制一样,得到了下一张具有500点的图像。这是代码

open3d()
plot3d(x0, y0, f(x0, y0), type = "p")

给出以下情节: enter image description here 我知道很难看这张静止图像,但是能够旋转采样正在起作用。

现在这是我的问题:如何使用plot3d(),以便我可以拥有一个将所有这些点连接起来并给出更精确的锯齿图的曲面?或我怎样才能使z轴上的每个点都相对于xy平面成条形?我只想要3维而不是点,我找不到如何做到这一点。

感谢您的帮助

3 个答案:

答案 0 :(得分:2)

您可以通过对表面进行三角测量来实现。您没有提供实际数据,但我可以使用

f = function(x, y){
    z = ((x^2)+(3*y^2))*exp(-(x^2)-(y^2))
}
x <- runif(500, -3, 3)
y <- runif(500, -3, 3)
z <- f(x, y)

然后使用?persp3d.deldir中的方法完成绘制:

library(deldir)
library(rgl)
col <- colorRampPalette(c("blue", "white"))(20)[1 + round(19*(z - min(z))/diff(range(z)))]
dxyz <- deldir::deldir(x, y, z = z, suppressMsge = TRUE)
persp3d(dxyz, col = col, front = "lines", back = "lines")

这可能需要一些修饰,例如

aspect3d(2, 2, 1)

经过一些旋转后,得到以下图:

enter image description here

答案 1 :(得分:0)

我不确定您想要什么。如果我的理解是正确的,这是一个解决方案。定义表面的参数表示形式:

namespace Largest_palindrome_product{

class Program
{
    static void Main(string[] args)
    {
        string Reverse(string s)
        {
            char[] charArray = s.ToCharArray();
            Array.Reverse(charArray);                
            return new string(charArray);
        }


        int result = 0;
        string rev= "hello";
        string palindrome = "hello";
        string bingo = "hello";
        int j = 1;
        for (int i = 1; i< 1000; i++)
        {
            for (int y = 1; y< 1000; y++)
            {
                result = i * y;
                bingo = result.ToString();
                rev = Reverse(bingo);
                j = int.Parse(bingo);
            }

            if (rev == bingo)
            {
                palindrome = bingo;
            }
        }
        Console.Write(palindrome);
        Console.Read();
    }
}

假设您有以下几点:

fx <- function(u,v) u
fy <- function(u,v) v
fz <- function(u,v){
  ((u^2)+(3*v^2))*exp(-(u^2)-(v^2))
}

然后,您可以使用x0 <- seq(-3, 3, length.out = 20) y0 <- seq(-3, 3, length.out = 20) 包的函数parametric3d,并选择misc3d来获得线框:

fill=FALSE

enter image description here

是您想要的吗?

要获取一些竖线,请使用library(misc3d) parametric3d(fx, fy, fz, u=x0, v=y0, color="blue", fill = FALSE) 中的函数segments3d

rgl

答案 2 :(得分:0)

使用我的原始代码,这里只有50点。

Scatter graph of 50 points

然后我应用斯特凡·洛朗(StéphaneLaurent)的话,然后得到这个图,如果给出我的实际分数,那感觉太准确了

wire plot

也许您需要向我解释parametric3d函数中实际上发生了什么

相关问题