Presume I have a line made up of two points on a 2D plane. We'll call the line AB, and it is drawn randomly with a random length and angle to the global X axis. I then need to draw line BC, which spans from the end of line AB and adds a new point: 'C'. This BC line needs to be constricted to a certain angle. The actual angle doesn't matter.
The green area represents the ambiguous area in which the next point can be drawn. Note that the length of the line should also be variable (i.e. the distance of point C from B).
EDIT: To clear things up, the allowed angle area should be influenced by the angle of the AB line against the global X
In short, the question is. How would I mathematically define an "allowed drawing space" for point C so it can be any variable length and be constrained within the green area. The green area should be influenced by the line AB, based on its angle to the global X.
Thanks!
Taking into account your objective, i.e., build a rather smooth broken line without sudden orientation changes, here is an algorithm that performs the work:
$\text{Initialisation} \ : \ \theta_0=0, \ x_0=0, \ y_0=0, \ n=500, \ a=0.2$
$\text{Repeat for } \ k=1 \ \text{to} \ n:$
$\begin{array}{l} \ \ \ \ \ \ \text{AngleVariation = (2*random - 1)}*a*\pi \\ \ \ \ \ \ \ \theta_{k+1} = \theta_{k} + \text{AngleVariation} \\ \ \ \ \ \ \ r_{k} = \text{random} \\ \ \ \ \ \ \ x_{k+1} = x_{k} + r_{k}*\cos(\theta_{k}) \\ \ \ \ \ \ \ y_{k+1} = y_{k} + r_{k}*\sin(\theta_{k}) \\ \ \ \ \ \ \ \text{plot segment line from point} (x_{k}, y_{k}) \ \text{to point} \ (x_{k+1}, y_{k+1}) \end{array}$
Explanation :
$a$, set here to $0.2$, is an adjustable parameter controlling the aperture of the angle.
"random" is a uniformly distributed number with value between $0$ and $1$. Every time it's called, it is a new random number that is generated. In this way "2*random - 1" is uniformly distributed between $-1$ and $1$.
the choice of the number of line segments $n=500$ is, of course, arbitrary.
$\pi$ (in radians) is the same as $180°$ (in degrees).
Illustration :
I have programmed the algorithm with Matlab. Here are two results, the first one with $a=0.1$, the second one with $a=0.3$, showing the influence of this parameter.