具有预先指定端点的分形生成线
这是我的问题:
我有两个随机点 (x,y) 和 (x2, y2)。我想在两者之间建立一个“随机步骤”或分形线。我设置了一种情况,其中步距和方向是根据概率矩阵随机生成的。然而,如果只考虑该矩阵的方向,该线将具有一个无法预先确定的随机端点。因此,我尝试为我的线设置边界,如果一个点落下,则位置会相应调整。这些界限不起作用。
理想情况下,我的边界是一个由该区域两端的每个随机点创建的圆。我已经尝试过以下方法。
我已经设置了一个循环,它将使用变量i迭代该线的每个x点,该变量从x和x2中较小的一个开始并向较大的方向移动。
我设置了一个变量j,随机步骤将添加到其中,并将其初始化为较小x值的等效y值(如果x1大于设置为y1,否则设置到 x)。
我设置了一个变量,其中包含 x,y 和 x1,y1 之间的理论直线的斜率。
我已经建立了一个概率矩阵,它采用变量 mod 并将其设置为 8 到 -8 之间的值。
我已设置检查以禁止在给定平面边界之外形成线条。
我已经设置了一个检查来确定变量i是否比x和x2中的较大者小1。如果是这样,变量 j 设置为该 x 值的 y 值;
正是在这一点上,我未能找到适当的算法来设置最终检查。以下是我希望算法执行的操作:
A. 我希望它能够在给定 x 和 x1 之间的随机 x 值的情况下,确定当前变量 j 是否添加到当前变量变量 mod 位于上述两个点生成的圆之外(参见第二段)。如果不是,请将 mod 添加到变量 j 并递增循环。
B. 如果该点超出范围,我希望反转步骤方向(例如 -6 到 6 和 2 到 -2),并再次进行相同的检查。
C. 如果向任一方向添加都会使其超出边界(这很可能发生在边界最窄的圆的远端附近),我希望能够运行一个循环来检查每个值并它的倒数从 0 开始并连续移动到更大的值,直到确定一个可行的值。
我希望有经验的数学家和程序员认为这是一个可以克服的挑战。它困扰了我三个星期,我已经没有想法了。
Here is my problem:
I have two random points (x,y) and (x2, y2). I would like to great a 'random-step' or fractal line between the two. I have set up a situation wherein the step distance and direction are randomly generated based on a probability matrix. However, leaving it solely to the direction of this matrix, the line will have a random endpoint which is impossible to pre-determine. I have therefore attempted to set up bounds for my line where--if a point falls--the location is adjusted accordingly. These bounds are not working.
Ideally, my boundaries would be a circle created with each random point at opposite ends of the area. I have tried the following.
I have set up a loop which will iterate through each x-point of the line using a variable i which starts with the lesser of x and x2 and moves towards the greater.
I have set up a variable j to which the random step will be added and initialised it to the equivalent y-value for the lesser x-value (if x1 is greater set to y1 else set to x).
I have set up a variable which contains the slope of the theoretical straight line between x,y and x1,y1.
I have set up a probability matrix which takes a variable mod and sets it to a value between 8 and -8.
I have set up checks to disallow the formation of the line outside of the boundaries of the given plane.
I have set up a check to determine if the variable i is one less than the greater of x and x2. If so, variable j is set to that x-value's y-value;
It is at this point that I fail to find the appropriate algorithm to set up the final check. Here is what I would like the algorithm to do:
A. I would like it to be able to, given a random x-value between x and x1, determine if the current variable j added to the current variable mod is outside of the circle generated by the two aforementioned points (see the second paragraph). If it is not, add mod to variable j and increment the loop.
B. If this point would fall outside the bounds, I would like the step direction to be reversed (e.g. -6 to 6 and 2 to -2) and the same check to be made again.
C. If adding in either direction would put it out of bounds (which will most likely happen near the far end of the circle where the boundaries constrict the most), I would like to be able to run through a loop which checks each value and its inverse beginning at 0 and moving to consecutively larger values until a workable value is determined.
I hope you experience mathematicians and programmers out there see this as a surmountable challenge. It has stumped me for three weeks and I have run out of ideas.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有一个更简单的方法。一个更简单的方法。
您已经知道您的端点。如果要在两个端点之间生成分形线,只需获取由两个端点定义的线段,然后通过在其间添加一个与当前线偏移随机量的新点将其分成两部分(改变这个量和偏移的方向将有效地定义分形的“形状”)。现在您有两条线段连接原始端点;为了增加随机性,请在两条线段中的每一条上重复。
There's an easier way. A MUCH easier way.
You already know your endpoints. If you want to generate a fractal line between your two endpoints, simply take the line segment that is defined by your two endpoints, and break it in two by adding a new point in between that is offset from the current line by a random amount (varying this amount and the direction that you offset by will effectively define the "shape" of your fractal). You now have two line segments which connect your original endpoints; for increased randomness, repeat on each of the two line segments.
创建分形边缘的通常方法是从一条直线开始,然后根据某种规则递归地细分,该规则可以是确定性的或非确定性的(即允许一定的随机性)。
根据您的要求,您可能需要注意您的规则不允许交叉线。在一条线和由其细分产生的线之间施加一些最大角度可能就足够了(我认为< 45°)。但不要引用我的话。
一个简单的算法是将线的中点垂直于线移动一段与线的长度成比例的随机距离。
The usual way to create fractal edges is to start with a straight line and recursively subdivide according to some rule, which can be deterministic or non-deterministic (i.e., allow some randomness).
Depending on your requirements, you may have to take care that your rule doesn't allow lines to cross. It may be sufficient to impose some maximum angle between a line and the lines that result from its subdivision (< 45°, I think). But don't quote me on that.
A simple algorithm for this is to displace the midpoint of the line perpendicularly to the line some random distance in proportion to the length of the line.
谷歌“空间填充曲线”,你会得到科赫雪花和一到二之间的分形维数,以及各种其他好东西。
Google ' space filling curve ', and you will get the Koch snowflake and fractal dimensions between one and two, and all sorts of other goodies.