直线转曲线

发布于 2024-11-05 02:56:20 字数 190 浏览 4 评论 0 原文

我正在尝试想出一种技术来生成流星陨石坑的高度图。目前我试图保持小而简单,并有一个简单的算法,其中标记了陨石坑的中心,并在其半径内,其周围的像素根据它们与中心的距离而着色。

这种方法的问题是它会产生 V 形坑,我需要更多的“U”形结果。我对正弦波的使用不熟悉,而且我觉得考虑到流星半径内可能有多少像素,插值不会很快工作。

有什么建议吗?

I am trying to come up with a technique to generate a height map for a meteor crater. I'm trying to keep is small and simple at the moment, and have a simple algorithm where the centre of the crater is marked, and within its radius, pixels around it are coloured depending on how close to the center they are.

The problem with this method is it is producing V shaped craters, I require more 'U' shaped results. I'm unfarmilliar with the use of sine waves and I get the feeling interpolation wont work very quickly given how many pixels could be inside the meteor radius.

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自此以后,行同陌路 2024-11-12 02:56:20

我假设您有一个纹理或其他图片格式,可以在宽度和高度 (x,y) 上进行索引,并且陨石坑也以 x,y 形式给出,其中 x,y 在纹理内,这将产生这样的算法。

Texture2D texture = ...;
Vector2 craterPosition = new Vector2(50,50);
double maxDistance = Math.Sqrt(Math.Pow(texture.Width,2) + Math.Pow(texture.Height,2));
for(int x = 0; x < texture.Width; x++)
{
    for(int y = 0; y < texture.Height; y++)
    {
        double distance = Math.Sqrt(Math.Pow(x - craterPosition.x, 2) + Math.Pow(y - craterPosition.y, 2));
        //the lower distance is, the more intense the impact of the crater should be
        //I don't know your color scheme, but let's assume that R=0.0f is the lowest point and R = 1.0f is the highest
        distance /= maxDistance;
        double height = (Math.Cos(distance * Math.Pi + Math.Pi) + 1.0) / 2.0;
        texture[x,y] = new Color((float)height,0,0,1);        
    }
}

这里最重要的一行可能是

double height = (Math.Cos(distance * Math.Pi + Math.Pi) + 1.0) / 2.0;

看看余弦曲线http://upload.wikimedia.org/wikipedia/commons/thumb/b/b6/Cos.svg/500px-Cos.svg.png 它有一个非常光滑的“火山口状”从 Pi 舍入到 TwoPi。由于我们的距离变量从 0~1 缩放,因此我们使用距离 *Pi + Pi。但这会给我们一个从 -1 到 1 的结果。因此,我们将最终结果加 1,然后除以 2,以获得 0 到 1 之间高度的平滑结果。

我希望这对您有所帮助。

I assume you have a texture or other picture format that can be indexed over width and height (x,y) and that the crater is also given in x,y with x,y inside the texture, this would produce an algorithm like this.

Texture2D texture = ...;
Vector2 craterPosition = new Vector2(50,50);
double maxDistance = Math.Sqrt(Math.Pow(texture.Width,2) + Math.Pow(texture.Height,2));
for(int x = 0; x < texture.Width; x++)
{
    for(int y = 0; y < texture.Height; y++)
    {
        double distance = Math.Sqrt(Math.Pow(x - craterPosition.x, 2) + Math.Pow(y - craterPosition.y, 2));
        //the lower distance is, the more intense the impact of the crater should be
        //I don't know your color scheme, but let's assume that R=0.0f is the lowest point and R = 1.0f is the highest
        distance /= maxDistance;
        double height = (Math.Cos(distance * Math.Pi + Math.Pi) + 1.0) / 2.0;
        texture[x,y] = new Color((float)height,0,0,1);        
    }
}

The most important line here is probably

double height = (Math.Cos(distance * Math.Pi + Math.Pi) + 1.0) / 2.0;

Take a look at the cosine curve http://upload.wikimedia.org/wikipedia/commons/thumb/b/b6/Cos.svg/500px-Cos.svg.png it has a nice smooth 'crater like' rounding from Pi to TwoPi. Since our distance variable is scaled from 0~1 we use distance *Pi + Pi. But this will give us a result from -1 to 1. So we add 1 to the end result and then divide by 2 to get a smooth result for the height between 0 and 1.

I hope this helps you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文