Recent heb ik de polygonen aanpak uitgebreid en een random factor toegevoegd. Hierdoor ontstaat deels een random walk (dronkemans loop). De effectieve cirkel omtrek word kleiner, ingezoomd ziet de omtrek willekeurig/kronkelig uit. Er is een treshold waarbij deze cirkels niet meer herkend kunnen worden. Uit mijn bevindingen blijken all deze gekke cirkels te bestaan indien men de treshold verlaagd.
Taal en schrijven is niet mijn specialiteit. Dus hier de Engelstalige versie welke gepost.
Next is the topic I worked on last week. It takes allot effort for me to create something, and making many mistakes but learning allot. I posted question also on SE because I think this topic potentially has more depth then know with my limited knowhow.
Math Stacks Exchange: Circle from (2D) random walk
A method is presented to create circles from sort of random walks. The hobby project is based upon two earlier topics: circles from \(n-\)gons with circumference: \(C=1\) [SE] or area: \(A=1\) [SE].
The \(n-\)gon formula can be extended with a random variable.
\(x(n)=\frac{1}{n} \sum_{k=1}^{q} \cos \left( \frac{X+2k}{n_{i}} \pi \right)\)
\(y(n)=\frac{1}{n} \sum_{k=1}^{q} \sin \left( \frac{Y+2k}{n_{i}} \pi \right)\)
The total step length or "circumference" is set to \(1\). Where \(n\) is the number of \(n-\)gon edges (and steps in the random walk). The summation is discrete with \(k\) usually till \(q=n\), completing a full circle till \(2\pi\). Two random (uniform distributed) variables are introduced: \(X\) and \(Y\). These random variables are defined as an element between: \([0,2]\) \(\pi\). The number of elements is determined by variable \(p\) such that:
\(p=2, \quad X \in \{0,2\} \quad \textrm{and} \quad Y \in \{0,2\}\)
\(p=3, \quad X \in \{0,1,2\} \quad \textrm{and} \quad Y \in \{0,1,2\}\)
\(p=4, \quad X \in \{0,\tfrac{2}{3},\tfrac{4}{3},2\} \quad \textrm{and} \quad Y \in \{0,\tfrac{2}{3},\tfrac{4}{3},2\}\)
\(etc.\)
When \(p=2\) we will get regular \(n-\)gons, while the elements \(0\) and \(\pm 2\pi\) have no effect on \(\sin\) and \(\cos\). When \(p>2\) the number of possible outcomes per step increases. A random walk effect can be observed.
In the video below the circle creation for \(p=2\) till \(6\) is presented. The random walk consists of \(N=1.000.000\) steps, \(k\) is listed as natural numbers from: \(1\) till \(1.000.000\). Every walk is displayed and looped over \(n_i\).
Several observations have been made (see normal picture below).
- For \(p=2\) the regular \(n-\)gons can be seen (triangle, square, pentagon...) left image GIF file.
- For \(p>2\) initially random walk structures are seen gradually (multiple) circles appear.
- After \(1.000.000\) steps single circles can be observed for all presented values of \(p\).
- The edges of all circles for \(p>2\) have rough and overlapping edges.
- The effective circle diameter decreases. Empirical: it is found that the circumference decreases with: \(1/p\) see picture.
- The effective walk length is calculated as the sum of all: \(\Delta r=\sqrt{\Delta x^2+\Delta y^2}\). Observation: the total path length for \(p>3\) is less than \(1\) on average: \(0.96\). This is one of key questions.
For the decrease in diameter, I came up with the following explanation. But not sure if it is completely valid (I struggled with $\arcsin$ distribution and various other deviations).
First assume \((1)\) as continuous and integrate:
\(x(n)=\frac{1}{n} \int \cos \left( \frac{X+2k}{n_{i}} \pi \right) dk = \frac{1}{2 \pi} \sin \left( \frac{X+2k}{n_{i}} \pi \right) \tag{2}\)
With the sum formula for cosine (and sine) formula \((2)\) can be rewritten:
\(x(n) = \frac{\sin \left( X \pi \right)}{2 \pi} \cdot \cos \left( \frac{2k}{n_{i}} \pi \right) + \frac{\cos \left( X \pi \right)}{2 \pi} \cdot \sin \left( \frac{2k}{n_{i}} \pi \right) \tag{3}\)
The random parts of the radius are: \(\sin \left( X \pi \right)\) and \(\cos \left( X \pi \right)\). These have influence on the radius.
After trial and error, I came up with the following formula calculating the mean radius error\( \Delta \bar{R}\) (not sure about this):
\(\Delta \bar{R_{x}}=\frac{1}{p} \sum_{m=0}^{p-1} \cos \left( \frac{ 2 \pi \ m }{p-1} \right) \)
\(\Delta \bar{R_{y}}=\frac{1}{p} \sum_{m=0}^{p-1} \sin \left( \frac{ 2 \pi \ m}{p-1} \right) \)
Found a solution with help of Wolfram Alpha:
\( \Delta \bar{R_{x}}= \frac{1}{2p} \left[ \sin \left( \frac{\pi p}{1-p}\right) \csc \left( \frac{\pi}{p-1} \right) +1 \right] \)
\(\Delta \bar{R_{y}}=\frac{1}{2p} \left[ \cos \left( \frac{\pi }{p-1}\right) +\cos \left( \frac{\pi p}{1-p}\right) \right] \csc \left(\frac{\pi}{p-1} \right) \)
When analyzing these functions (discrete \(p\)) I found that \(\Delta \bar{R_{x}}\) decreases with \(1/p\) just like the simulation. However the \(\Delta \bar{R_{y}}\) seems to be \(0\) for discrete values of \(p\). Not sure but then formula \((3)\) (and \(y\) counter part) simplifies. Also: there exists no solution for \(p=2\) according Wolfram Alpha in this context. So, for \(p>2\):
\(\boxed {x(n) = \frac{1}{2 \pi p} \cdot \sin \left( \frac{2k}{n_{i}} \pi \right) \\ y(n) = - \frac{1}{2 \pi p} \cdot \cos \left( \frac{2k}{n_{i}} \pi \right)}\)
I would like to have feedback if method is acceptable thus far. Note that this is a hobby project by amateur.
Open question:
- How can the total path length be smaller for random walk circles? I observed that when the random variables for axis \(x\) and \(y\) are equal: \(X=Y\) then the total path lengt is: \(1\).
- Do all presented random walk circles exists for $p \rightarrow \infty$ and the number of steps is infinate?
Code: Selecteer alles
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, figsize=(12,12))
ax.axis('equal')
n=10000
steps=10000
p=4
N=np.arange(0,steps)
t=N/n
px=2*np.random.choice(p,steps)/(p-1)
py=2*np.random.choice(p,steps)/(p-1)
x=1/(steps)*np.cos((px+t*2)*np.pi)
x=np.append(x,x[0])
y=1/(steps)*np.sin((py+t*2)*np.pi)
y=np.append(y,y[0])
xc=np.cumsum(x)
yc=np.cumsum(y)
xd=np.diff(xc)
yd=np.diff(yc)
dr=np.sqrt(xd**2+yd**2)
circum=np.sum(dr)
ax.plot(xc[:n],yc[:n],linewidth=0.15,color='black')
plt.show()