Perli 噪声 - 散列函数不返回相同的向量

问题描述

我正在尝试使用置换表和散列函数来实现柏林噪声。

散列函数应该为网格点返回相同的向量,但它似乎没有这样做。

我用一个小的排列表做了一些测试 P = [0,3,1,2] 其中值 0 到 3 然后用于分配向量

def get_constant_vector(p):
    # p is the value from the permutation table
    h = p % 3 # p & 3
    
    if h == 0:
        return [1.0,1.0]
    elif h == 1:
        return [-1.0,1.0]
    elif h == 2:
        return [1.0,-1.0]
    else:
        return [-1.0,-1.0]

所以如果表中的值相同并且向量也相同。 这就是我如何从一个点周围的边界框的每个角的排列表中确定值。

P = [0,2]
P = P * 42 # to absolutely prevent index out of range

for x in range(5):
    x = x + 0.5
    for y in range(5):
        y = y + 0.5

        X = int(x) % 4
        Y = int(y) % 4
        
        value_TL = P[P[X] + Y + 1] # top left corner
        value_TR = P[P[X + 1] + Y + 1] # top right corner
        value_BR = P[P[X + 1] + Y] # bottom right corner
        value_BL = P[P[X] + Y] # bottom left corner
        
        print(f"x={x},y={y},BL = {value_BL},BR = {value_BR},TL = {value_TL},TR = {value_TR}")

这会产生以下结果:

x=1.5,y=1.5,BL = 0,BR = 1,TL = 3,TR = 2    vector here is BR   1
x=1.5,y=2.5,BL = 3,BR = 2,TL = 1,TR = 0    vector here is TR   0
x=2.5,BL = 1,TL = 2,TR = 0    vector here is BL   1
x=2.5,BL = 2,BR = 0,TL = 0,TR = 3    vector here is TL   0

他们认为是一样的,但事实并非如此。

我的假设哪里错了?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)