如何生成这种随机曲线?

发布于 2024-11-19 11:58:40 字数 473 浏览 1 评论 0原文

是否可以生成这种随机曲线?

在此处输入图像描述

我尝试过 IMagick 贝塞尔曲线(请参阅 http://www.php.net/manual/en/function.imagickdraw-bezier.php),但是即使有20-30分,他们看起来也不是这样的。这是我的示例 http://mechanicalzilla.com/sandbox/imagick/curve.php

谢谢。

Is it possible to generate this kind of random curves?

enter image description here

I've tried IMagick bezier curves (see http://www.php.net/manual/en/function.imagickdraw-bezier.php), but even with 20-30 points they do not look like this. Here is my sample http://mechanicalzilla.com/sandbox/imagick/curve.php

Thank you.

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

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

发布评论

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

评论(4

裂开嘴轻声笑有多痛 2024-11-26 11:58:41

看起来像:

x = 0; y = 0; angel = 0;
while (true) {
   angel = angel + 0.5 - random(1);
   x1 = x + 0.1 * cos(angel);
   y1 = y + 0.1 * sin(angel);
   if (abs(x1 - x) + abs(y1 - y) < 10)
     drawline(x,y,x1,y1);
   x = x1; y = y1;

   if (x < 0) x = width;
   if (y < 0) y = height;
   if (x > width) x = 0;
   if (y > height) y = 0;
}

在此处输入图像描述

Looks like:

x = 0; y = 0; angel = 0;
while (true) {
   angel = angel + 0.5 - random(1);
   x1 = x + 0.1 * cos(angel);
   y1 = y + 0.1 * sin(angel);
   if (abs(x1 - x) + abs(y1 - y) < 10)
     drawline(x,y,x1,y1);
   x = x1; y = y1;

   if (x < 0) x = width;
   if (y < 0) y = height;
   if (x > width) x = 0;
   if (y > height) y = 0;
}

enter image description here

白鸥掠海 2024-11-26 11:58:41

这远不是一个完整的答案,但在我看来,它似乎可以帮助您:

不要从整条线的起点到终点绘制曲线,而是考虑将板细分为均匀间隔的网格。网格的一列的每个方格都有权在其中包含一条曲线的一个点,并且您将从左向右稳步前进(一开始?为了简单起见。)。

随机性将通过为曲线选择一个正方形来发挥作用 - 为了防止它变得太混乱,你可以给这个随机性界限,比如说,“你不能选择一个正方形(如果正方形到正方形的距离)被认为是1)违反了abs(当前垂直位置 - 新垂直位置)<= 5,除非此时不再有这样的自由”或其他任意限制。 (“除非此时不再免费”很重要,否则可能会将自己锁定在无法解决的状态。)

(抱歉,用鼠标绘制曲线 -> 最差/没有插值。不过,我想,Catmull-Rom 插值可能会是你的朋友。

应该足够宽松,因为你的曲线点不能在给定的网格中任意分散在一起,但是让曲线“流畅地”连接到终点可能非常困难 - 如果你不过,不要介意任意端点,因为算法可以自行决定线路的结束位置。

认为这个想法可以帮助您塑造曲线吗?

This is far from a complete answer, but in my mind's eye seems like it could help you:

Instead of drawing curves from the start to the end point of the entire line, consider subdividing your board into a evenly spaced grid. Each square of one column of the grid is entitled to have one point of one curve in it, and you'd steadily advance from left to right (at first? for simplicity's sake.).

The randomness would come into play by picking a square for a curve - to prevent it from getting too chaotic, you could give this randomness bounds, say, "you're not allowed to pick a square that (if a distance from square to square is considered 1) violates abs(current vertical position - new vertical position) <= 5 unless none such is free anymore at this point" or some other arbitrary restraint. ("unless none such is free anymore at this point" is important, otherwise it's possible to lock yourself into an unsolvable state.)

Two example curves generated this way.

(Sorry, drawing curves with my mouse -> worst/no interpolation ever. Catmull-Rom interpolation will probably be your friend here, though, I imagine.)

The display should be loose enough given that your curve points cannot arbitrarily scatter together given a grid, but it's probably very difficult to get the curve to connect to the end point 'fluidly' - might be a good solution if you don't mind arbitrary end points, though, read as, the algorithm can decide for itself where it wants the line to end.

Think this idea might help you with your curves?

盛夏已如深秋| 2024-11-26 11:58:41

解决这个问题的一种方法是首先生成一组随机曲线,然后使用物理解算器在它们之间施加排斥力以避免结块。

以下是概念的快速证明:

noodle curve

我使用一个非常利基的工具创建了这个(对于任何感兴趣的人:袋鼠物理解算器Grasshopper 的插件,可视化脚本语言Rhinoceros3d),但您可能可以在任何主流编程语言中重新创建相同的概念,例如。 Python。

One way to approach this would be to first generate a set of random curves and then use a physics solver to apply repulsion forces between them to avoid clumping.

Here's a quick proof of concept:

noodle curves

I created this using a very niche tool (for anyone interested: Kangaroo Physics solver, a plugin for Grasshopper, visual scripting language for Rhinoceros3d) but you can probably recreate the same concept in any mainstream programming language, eg. Python.

亽野灬性zι浪 2024-11-26 11:58:40

我打赌你可以编写一个算法,在直接到达出口坐标之前,该算法基本上会进行 x 次随机扭曲。这还假设算法足够聪明,可以检查转弯的角度。 (假设你不想最终陷入结网)

但是,假设这不是你的毕业任务,或者你是按小时付费从事这项工作,这将是浪费时间,成功就是非常值得怀疑。

即使您能够设法生成单线算法,但要使线条不会彼此靠得太近几乎是不可能的。你最终会得到这样的结果: knot-web

I bet you could write an algorithm which would basically take x number of random twists before going straight to the exit coordinates. This also assumes that algorithm is smart enough to check the angle of the turn. (assuming you don't want to endup in knot-web)

However, assuming that this isn't your graduation task or that you are paid on per-hour basis to work on this, this would be a waste of time and success is highly doubtful.

Even if you'd manage to generate single line algorithm, doing it so that the lines wouldn't come too close to each other is close to impossible. You will end up with something like this: knot-web

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