Edited by Valentin Fadeev, Thursday, 15 Apr 2010, 00:21
I have always been amazed by the power of recurrent formulas. Although they are likely to cause stack overflow (this was the first occasion when i learned what it actually means), used carefully they deliver beautiful results.
I once amused myself drawing stellar polygons of arbitrary number of vertices. That required a simple parametrized procedure that produced a sequence of vertices to be connected with line segments.
Starting with the formula of the n-th root of complex number (of unitary modulus):
MathJax failure: TeX parse error: Extra open brace or missing close brace
to get the coordinates of the n vertices, i found the following way to produce the path sequence:
where is the number of the vertex and d () is the number of vertices "skipped" in one step.
So the procedure looks roughly like this:
x0=cos(phi/n)
y0=sin(phi/n)
do
vn=(v+d) mod n
x1=cos((phi+2*pi*vn)/n)
y1=sin((phi+2*pi*vn)/n)
line(x0,y0)-(x1,y1)
v=vn
x0=x1
y0=y1
loop until vn=0
I even considered the idea of enumerating the possible outcomes for different pairs of (n,d), but put it on the shelf then..
Return of the recurrencies
I have always been amazed by the power of recurrent formulas. Although they are likely to cause stack overflow (this was the first occasion when i learned what it actually means), used carefully they deliver beautiful results.
I once amused myself drawing stellar polygons of arbitrary number of vertices. That required a simple parametrized procedure that produced a sequence of vertices to be connected with line segments.
Starting with the formula of the n-th root of complex number (of unitary modulus):
MathJax failure: TeX parse error: Extra open brace or missing close brace
to get the coordinates of the n vertices, i found the following way to produce the path sequence:
where is the number of the vertex and d () is the number of vertices "skipped" in one step.
So the procedure looks roughly like this:
x0=cos(phi/n)
y0=sin(phi/n)
do
vn=(v+d) mod n
x1=cos((phi+2*pi*vn)/n)
y1=sin((phi+2*pi*vn)/n)
line(x0,y0)-(x1,y1)
v=vn
x0=x1
y0=y1
loop until vn=0
I even considered the idea of enumerating the possible outcomes for different pairs of (n,d), but put it on the shelf then..