什么是一个很好的方式来产生随机集群和路径? [英] What's a good way to generate random clusters and paths?

查看:163
本文介绍了什么是一个很好的方式来产生随机集群和路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我玩弄周围写一个随机地图生成,并不太清楚如何随机生成逼真的风景。我正与这些类型的当地比例尺地图,其中presents一些有趣的问题。

其中一个最简单的情况下是<一个href="http://www.d20pfsrd.com/gamemastering---final/environment---final/wilderness#TOC-Forest-Terrain">forest:

 稀疏中密
典型树木50%70%80%
大规模的树木 -  10%20%
林下轻50%70%50%
重林下 -  20%50%
 

树木和灌木丛可以在同一个空间存在,所以平均疏林地有25%的典型树和光林下,25%的典型树,25%的光灌木丛,和25%的开放空间。中型和茂密的森林将采取多一点思考,但它不是在我的问题所在要么,因为这一切都均匀地分散。

我的问题在于在产生簇和路径,同时保持百分比的限制。 <一href="http://www.d20pfsrd.com/gamemastering---final/environment---final/wilderness#TOC-Marsh-Terrain">Marshes是一个很好的例子:

 沼泽沼泽
浅沼泽20%40%
深沼泽5%20%
林下轻30%,20%
重林下10%20%
 

  

深沼泽广场是由浅沼泽广场的不规则的环形通常聚集在一起,围绕着。

这是额外的地图元件,绿篱,也可以是present,以及开放地的路径,通过沼泽蜿蜒。这两种类型的地图要素(簇和路径)present问题的,作为地图的总组合物应包含元件的X%,但它不是均匀分布的。其它元素,如流,池塘和流沙需要或者群集或路径型代以及

我可以使用哪些技术来生成考虑到这些限制的现实映射?


我使用C#,仅供参考(但这不是一个C#特异性的问题。)

使用解决方案

现实随机分配往往是做href="http://en.wikipedia.org/wiki/Perlin_noise"> 培林噪音 ,它可以被用来给分布,像你提到的团块。它的工作原理是加/随机数据点相结合的线性插值的多个层。每个层(或八度)的两倍多的数据点作为最后,并局限在一个窄的范围内的值。其结果是现实的寻找随机纹理。

下面是 背后柏林噪声理论 雨果埃利亚斯。

下面是我发现柏林噪声在C#中的第一件事。

你可以做的就是生成Perlin杂点图像,并设置一个门槛,其中任何一个以上的值为on,一切都在它下面是关闭。你将最终获得的团块,事情都高于阈值,看起来不规则,真棒。只要将上面的门槛,您希望您的地形特征是的。

这里是一个演示如果程序产生一个柏林噪声位图,然后调整截止阈值随着时间的推移。一个明显的聚集是可见的。这可能是你想要什么。

注意,具有高门槛,很少点上方,这是稀疏。但随着门槛降低,这些点长大成团块(由Perlin杂的性质),其中一些团块将加入海誓山盟,基本上创造一些非常自然和地形等。

请注意,您还可以设置丛因素,或功能聚集,通过设置您的柏林噪声的功能,这基本上使峰值和您PN功能谷的动荡的倾向进行强调和更密切在一起。

现在,在哪里设置的门槛?的阈值高,较低的特征的最终地图上的百分比。阈值越低,该百分比越高。你可以摆弄它们。你也许可以得到准确的百分比由一点点数学摆弄周围(似乎值的分布遵循正态分布;我可能是错的)。调整它,直到它的恰到好处:)

修改正如在评论中,你可以找到通过创建一个累积直方图(是下一个门槛是什么%的地图索引)的准确率和挑选,让你的门槛%的需要。

这里的最酷的事情是,你可以创建一个围绕某些其他功能聚集(如您的沼泽功能)平凡这里的功能 - 只要使用相同的柏林噪声地图两次 - 第二次,降低门槛。第一个将是块状,而第二个将是大约在同一区域块状,但随着扩大的团块(参照flash动画早期公布)。

至于其他功能,如灌木篱墙,你可以尝试造型简洁随机游走线比转,并将它们放置在任何地方随意在你的培林为基础的地图。


样品

下面是一个简单的50×50片疏林地图。林下是棕色和树木的颜色为蓝色(对不起)要分清楚哪个是哪个。

有关本地图我没有确切的阈值,以匹配50%;我只设置阈值在最大的50%。据统计,这将会平均到每一次整整50%。但它可能是不够准确的为你的目的;请参阅前面的音符如何做到这一点。


下面是你马什功能演示(不包括丛林,为清楚起见),浅沼泽灰色和深沼在后面:

这仅仅是50×50,所以有一些文物从,但你可以看到你可以多么容易浅水沼泽从深沼成长 - 简单地通过调整同一培林地图上的门槛。对于这一个,我eyeballed的阈值水平给予最赏心悦目的效果,但对于自己的目的,你可以做什么之前提到的。

下面是来自同一个柏林噪声地图产生的沼地图,但伸在250X250瓷砖的地图,而不是:

I'm toying around with writing a random map generator, and am not quite sure how to randomly generate realistic landscapes. I'm working with these sorts of local-scale maps, which presents some interesting problems.

One of the simplest cases is the forest:

                    Sparse  Medium  Dense
Typical trees       50%     70%     80%
Massive trees       —       10%     20%
Light undergrowth   50%     70%     50%
Heavy undergrowth   —       20%     50%

Trees and undergrowth can exist in the same space, so an average sparse forest has 25% typical trees and light undergrowth, 25% typical trees, 25% light undergrowth, and 25% open space. Medium and dense forests will take a bit more thinking, but it's not where my problem lies either, as it's all evenly dispersed.

My problem lies in generating clusters and paths, while keeping the percentage constraints. Marshes are a good example of this:

                    Moor  Swamp
Shallow bog         20%   40%
Deep bog            5%    20%
Light undergrowth   30%   20%
Heavy undergrowth   10%   20%

Deep bog squares are usually clustered together and surrounded by an irregular ring of shallow bog squares.

An additional map element, a hedgerow, may also be present, as well as a path of open ground, snaking through the bog. Both of these types of map elements (clusters and paths) present problems, as the total composition of the map should contain X% of the element, but it's not evenly distributed. Other elements, such as streams, ponds, and quicksand need either a cluster or path-type generation as well.

What technique can I use to generate realistic maps given these constraints?


I'm using C#, FYI (but this isn't a C#-specific question.)

解决方案

Realistic "random" distribution is often done using Perlin Noise, which can be used to give a distribution with "clumps" like you mention. It works by summing/combining multiple layers of linearly interpolated values from random data points. Each layer (or "octave") has twice as many data points as the last, and confined to a narrower range of values. The result is "realistic" looking random texture.

Here is a beautiful demonstration of the theory behind Perlin Noise by Hugo Elias.

Here is the first thing I found on Perlin Noise in C#.

What you can do is generate a Perlin Noise image and set a "threshold", where anything above a value is "on" and everything below it is "off". What you will end up with is clumps where things are above the threshold, which look irregular and awesome. Simply assign the ones above the threshold to where you want your terrain feature to be.

Here is a demonstration if a program generating a Perlin Noise bitmap and then adjusting the cut-off threshold over time. A clear "clumping" is visible. It could be just what you wanted.

Notice that, with a high threshold, very few points are above it, and it's sparse. But as the threshold lowers, those points "grow" into clumps (by the nature of perlin noise), and some of these clumps will join eachother, and basically create something very natural and terrain-like.

Note that you could also set the "clump factor", or the tendency of features to clump, by setting the "turbulence" of your Perlin Noise function, which basically causes peaks and valleys of your PN function to be accentuated and closer together.

Now, where to set the threshold? The higher the threshold, the lower the percentage of the feature on the final map. The lower the threshold, the higher the percentage. You can mess around with them. You could probably get exact percentages by fiddling around with a little math (it seems that the distribution of values follows a Normal Distribution; I could be wrong). Tweak it until it's just right :)

EDIT As pointed out in the comments, you can find the exact percentage by creating a cumulative histogram (index of what % of the map is under a threshold) and pick the threshold that gives you the percent you need.

The coolest thing here is that you can create features that clump around certain other features (like your marsh features) trivially here -- just use the same Perlin Noise map twice -- the second time, lowering the threshold. The first one will be clumpy, and the second one will be clumpy around the same areas, but with the clumps enlarged (refer to the flash animation posted earlier).

As for other features like hedgerows, you could try modeling simple random walk lines that have a higher tendency to go straight than turn, and place them anywhere randomly on your perlin-based map.


samples

Here is a sample 50x50 tile Sparse Forest Map. The undergrowth is colored brown and the trees are colored blue (sorry) to make it clear which is which.

For this map I didn't make exact thresholds to match 50%; I only set the threshold at 50% of the maximum. Statistically, this will average out to exactly 50% every time. But it might not be exact enough for your purposes; see the earlier note for how to do this.


Here is a demo of your Marsh features (not including undergrowth, for clarity), with shallow marsh in grey and deep marsh in back:

This is just 50x50, so there are some artifacts from that, but you can see how easily you can make the shallow marsh "grow" from the deep marsh -- simply by adjusting the threshold on the same Perlin map. For this one, I eyeballed the threshold level to give the most eye-pleasing results, but for your own purposes, you could do what was mentioned before.

Here is a marsh map generated from the same Perlin Noise map, but on stretched out over 250x250 tiled map instead:

这篇关于什么是一个很好的方式来产生随机集群和路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆