RPerlin噪声中的逼真模拟高程数据

RPerlin噪声中的逼真模拟高程数据,第1张

概述有谁知道如何在R中创建模拟栅格高程数据集 – 即实际高程值的2d矩阵? R的抖动似乎不合适.在 Java / Processing中,noise()函数使用 Perlin noise算法实现了这一点,例如: size(200, 200);float ns = 0.03; // for scalingfor (float i=0; i<200; i++) { for (float j=0; 有谁知道如何在R中创建模拟栅格高程数据集 – 即实际高程值的2d矩阵? R的抖动似乎不合适.在 Java / Processing中,noise()函数使用 Perlin noise算法实现了这一点,例如:

size(200,200);float ns = 0.03; // for scalingfor (float i=0; i<200; i++) {  for (float j=0; j<200; j++) {    stroke(noise(i*ns,j*ns) * 255);    point(i,j);  }}

但我发现R文献中没有提到Perlin噪音.提前致谢.

解决方法 这是R中的一个实现,
按照说明进行
http://webstaff.itn.liu.se/~stegu/TNM022-2005/perlinnoiselinks/perlin-noise-math-faq.html

perlin_noise <- function(   n = 5,m = 7,# Size of the grID for the vector fIEld  N = 100,M = 100   # Dimension of the image) {  # For each point on this n*m grID,choose a unit 1 vector  vector_fIEld <- apply(    array( rnorm( 2 * n * m ),dim = c(2,n,m) ),2:3,function(u) u / sqrt(sum(u^2))  )  f <- function(x,y) {    # Find the grID cell in which the point (x,y) is    i <- floor(x)    j <- floor(y)    stopifnot( i >= 1 || j >= 1 || i < n || j < m )    # The 4 vectors,from the vector fIEld,at the vertices of the square    v1 <- vector_fIEld[,i,j]    v2 <- vector_fIEld[,i+1,j]    v3 <- vector_fIEld[,j+1]    v4 <- vector_fIEld[,j+1]    # Vectors from the point to the vertices    u1 <- c(x,y) - c(i,j)    u2 <- c(x,y) - c(i+1,j)    u3 <- c(x,j+1)    u4 <- c(x,j+1)    # Scalar products    a1 <- sum( v1 * u1 )    a2 <- sum( v2 * u2 )    a3 <- sum( v3 * u3 )    a4 <- sum( v4 * u4 )    # Weighted average of the scalar products    s <- function(p) 3 * p^2 - 2 * p^3    p <- s( x - i )    q <- s( y - j )    b1 <- (1-p)*a1 + P*a2    b2 <- (1-p)*a3 + P*a4    (1-q) * b1 + q * b2  }  xs <- seq(from = 1,to = n,length = N+1)[-(N+1)]  ys <- seq(from = 1,to = m,length = M+1)[-(M+1)]  outer( xs,ys,Vectorize(f) )}image( perlin_noise() )

通过添加这些矩阵,您可以拥有更多的分形结构,
具有不同的网格尺寸.

a <- .6k <- 8m <- perlin_noise(2,2,2^k,2^k)for( i in 2:k )  m <- m + a^i * perlin_noise(2^i,2^i,2^k)image(m)m[] <- rank(m) # Histogram equalizationimage(m)
总结

以上是内存溢出为你收集整理的R / Perlin噪声中的逼真模拟高程数据全部内容,希望文章能够帮你解决R / Perlin噪声中的逼真模拟高程数据所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1270001.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存