How to generate such random curves?

Is it possible to generate such random curves?

enter image description here

I tried IMagick bezier curves (see http://www.php.net/manual/en/function.imagickdraw-bezier.php ), but even with 20-30 points they don't look right, Here is my example http: // mechanicalzilla.com/sandbox/imagick/curve.php

Thanks.

+6
source share
3 answers

I bet you could write an algorithm that basically would take x number of random turns before going straight to the exit coordinates. It also suggests that the algorithm is smart enough to check the angle of rotation. (assuming you don't want to end up on a host)

However, believing that this is not your task for graduates or that you are paid an hour to work on it, this would be a waste of time, and success is very dubious.

Even if you manage to create an algorithm with one line, make it so that the lines are not too close to each other are close to impossible. You will get something like this: knot-web

+5
source

This is far from a complete answer, but in my opinion, it seems that it can help you:

Instead of drawing curves from start to end point of the entire line, consider dividing your board into a uniformly distributed grid. Each square of one column of the grid has the right to have one point of one curve in it, and you will steadily move from left to right (first for the sake of simplicity).

Randomness comes into play by choosing a square for the curve - so that it does not become too chaotic, you could give this estimate of randomness, say, "you are not allowed to choose a square that (if the distance from square to square is considered 1 ) violates abs(current vertical position - new vertical position) <= 5 if at this moment none of them is free "or some other arbitrary restriction. ("If none of them is free anymore at this stage," it’s important, otherwise you can block yourself in an unsolvable state.)

Two example curves generated this way.

(Sorry, drawing curves with my mouse -> worst / some interpolation ever. Catmull-Rom interpolation is likely to be your friend here, though, I think.)

The display should be free enough if your points in the curve cannot be randomly scattered along with the grid, but it is probably very difficult to make the curve connect to the end point β€œflowing” - it may be a good solution, t mind arbitrary end points, although read how, the algorithm can decide for itself where it wants the line to end.

Think this idea can help you with your curves?

+4
source

It 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

+3
source

Source: https://habr.com/ru/post/892561/


All Articles