I need help for developing an algorithm.
I'm drawing a given amount of line segments and I want them to decrese in length the more they get close to amount/2 and then to grow again until they reach the end of the loop. The data I have are the amount of segments, the segment-min-length and the segment-max-length.
I think that this could be done with a quadratic equation with the vertex in coordinates (segments-amount/2,segment-min-length) and with the left arm of the graph intersecting the y-axis at coordinates (0,segment-max-length) and the right arm of the graph intersecting the vertical imaginary line drawn at x = segments-amount.
Now the challenge is to get this quadratic equation dynamically given these data (segment amount, segment-min-length, segment-max-length).
And that's where I am stuck. How do I get the equation with these data?
If I haven't been clear enough please comment and I'll edit the question.
Thank you in advance!
$$ y=a(x-b)^2+c $$
You say you want the minimum at $x=\frac{N}{2}$, I'm going to take the minimum at $\frac{N+1}{2}$ which is the standard middle value expression. Therefore $b=\frac{N+1}{2}$.
You want that minimum value to be $L_{min}$ so $c=L_{min}$.
Now if $N$ is even, this will produce a smallest line segment bigger than $L_{min}$, but perhaps the problem can admit such a solution. If not, you'll need to differentiate between $N$ odd and $N$ even in your code. When $N$ is even yoll need to live with an asymmetry in your lengths i.e. for $N=6$, taking $N=3$ to be the smallest length $L_{min}$, the first length will be smaller than the last length. You'll need to take that into account when finding $a$.
Substitution of the point $(N,L_{max})$ (realise that if $N$ even and you took $N=4$ to be the smallest length then you need to consider the point $(1,L_{max})$. Then
$$ L_{max}=a\left(N-\frac{(N+1)}{2}\right)^2+L_{min} $$
$$ a = \frac{4(L_{max}-L_{min})}{(N-1)^2}$$
So your on the fly formula is
$$ y= \frac{4(L_{max}-L_{min})}{(N-1)^2}\left(x-\frac{(N+1)}{2}\right)^2+L_{min} $$