Perlin噪声的不连续导数

时间:2015-10-11 19:45:30

标签: java math perlin-noise

所以我最近一直试图实施Perlin噪音,并遇到了一些不寻常的问题。每当存储随机向量的网格边缘交叉时,导数似乎是不连续的。

这里是输出图片(右侧)的链接,以及1维切片(左侧)。

The Output

class perlin{
private double[][][] grid;
public perlin(int x,int y, int seed){
    Random r = new Random(seed);
    grid = new double[x+1][y+1][2];
    for(int i=0;i<grid.length;i++){
        for(int j=0;j<grid[0].length;j++){
            grid[i][j][0] = 2*r.nextDouble()-1;
            grid[i][j][1] = 2*r.nextDouble()-1;
        }
    }
}
public static double lerp(double a, double b, double t){
    double c = t * t * t * (t * (t * 6 - 15) + 10);
    return (b * c) + (a * (1 - c));
}
public double get(double x, double y){
    double x2;
    double y2;
    double x3;
    double y3;
    x2 = x * (grid.length-1);
    y2 = y * (grid[0].length-1);
    x3 = down(x2);
    y3 = down(y2);
    x2 = x2 - x3;
    y2 = y2 - y3;
    int i = (int) (x3);
    int j = (int) (y3);
    return lerp(lerp(dot(x2, y2, grid[i][j][0], grid[i][j][1] ), dot(1 - x2, y2, grid[i + 1][j][0], grid[i + 1][j][1]),x2), lerp(dot(x2, 1 - y2, grid[i][j + 1][0], grid[i][j +1][1] ), dot(1 - x2,1 -  y2, grid[i + 1][j + 1][0], grid[i + 1][j + 1][1] ), x2),y2 );
//  return 0;
}
public static double dot(double x1, double y1, double x2, double y2){
    return x1 * x2 + y1 * y2;
}
private static double down(double a){
    if (a == 0){
        return 0;
    }
    if(a == Math.floor(a)){
        return a - 1;
    }else{
        return Math.floor(a);
    }
}
}

根据我对这背后的数学的理解,噪声的导数应该在所有点都是连续的,但情况似乎并非如此。

0 个答案:

没有答案