小编Mic*_*007的帖子

2D Perlin噪音

我已经完全掌握了3D中Perlin Noise的艺术,现在我正在尝试将相同的实现用于2D算法.问题似乎在于选择我的渐变方向.在3D中,我在均匀分布的方向上使用16个渐变,这非常有用.在2D我想我会使用8个渐变.上,下,左,右和四个对角线方向.

这是我得到的:

在此输入图像描述

噪声的一般外观总是正确的,但正方形的边缘并不完全匹配.我也尝试使用其他渐变或更少的渐变,但得到类似的结果.在另一个例子中,您可以看到边缘有时会匹配,并且该区域的结果很好 -

在此输入图像描述

当我不使用渐变而只是在4个角中的每个角落随机拾取的值之间进行插值时,我得到了正确的结果,这就是让我觉得渐变部分会弄乱它的原因.

这是我的代码:

//8 different gradient directions
private Point[] grads = new Point[] { 
    new Point(0, 1), new Point(1, 1), new Point(1, 0), new Point(1, -1), 
    new Point(0, -1), new Point(-1, -1), new Point(-1, 0), new Point(-1, 1),};

//takes the dot product of a gradient and (x, y)
private float dot2D(int i, float x, float y)
{
    return
        grads[i].X * x + grads[i].Y * y;
}

public float Noise2D(float x, float y)
{
    int
        ix = …
Run Code Online (Sandbox Code Playgroud)

c# noise

14
推荐指数
3
解决办法
1万
查看次数

modify binary search to find the next bigger item than the key

I want to modify the famous binary search algorithm to return the index of the next bigger item instead of the key being searched.

So we have 4 cases:

  1. the key is smaller than all items, return 0.
  2. the key is bigger than all items, return items.length.
  3. the key is found at index x, return x+1.
  4. the key isn't found, return the index of the next bigger one.

e.g:

data = { 1, 3, 5, 7, 9, 11 };
Run Code Online (Sandbox Code Playgroud)
  • search …

algorithm binary-search

2
推荐指数
2
解决办法
9404
查看次数

标签 统计

algorithm ×1

binary-search ×1

c# ×1

noise ×1