How to generate a set of points that are equidistant from each other and lie on a normal distribution

272 Views Asked by At

I am trying to generate n points on a normal distribution(say, mean \mu and standard deviation \sigma) that are equidistant(Let's say the distance between pints is d) from each other in C. Points at normal distribution are from (-3\sigma + \mu) to (3\sigma + \mu). I am trying to have beads on the Gaussian curve, where beads are at equal distance (curved length).

Thank you in advance for the answer.

1

There are 1 best solutions below

2
On BEST ANSWER

Curve length of a function in $x$ can be found as

$$\ell_f(a, b) =\int_a^b \sqrt{1+\left(\frac{df(x)}{dx}\right)^2}dx$$

Which is nasty enough that in general we don't get an integrable result out of it; in our case we need to perform the integral and then invert it, and this is a recipe for sadness.

So what we'll do instead of this is do it numerically, replacing integration with the Riemann sum and differentiation with the difference quotient and doing a little simplifying.

$$\ell_f(a, b) = \lim_{\Delta x \rightarrow 0} \sum_{t=\frac{a}{\Delta x} + 1}^{\frac{b}{\Delta x}}\sqrt{\Delta x^2+\left(f(t\Delta x)-f((t-1)\Delta x)\right)^2}$$

Which still looks kinda mean but is possible to plug & chug by picking a reasonable value for $\Delta x$.

Of course, that only works forward, and we have to work backwards. Our best bet, since this is a series, is to do linear interpolation: draw straight lines between the points that make up the series. This gives a monotonic piecewise linear function, which is trivial to invert.

The procedure

We have our function $f(x)$, a low and high end of the interval in question $p$ and $q$, and a number of intervals to break the function into $n$.

Calculate $\Delta x = \frac{q-p}{n}$

For each integer $k$, $x_k = a + k\Delta x$, $y_k = f(x_k)$.

$d_k = \sqrt{(x_k - x_{k-1})^2 + (y_k - y_{k-1})^2} = \sqrt{\Delta x^2 + (y_k - y_{k-1})^2} $

$\ell_k = \sum_{i=1}^{k} d_k$

$m_k = \frac{\Delta x}{d_k}$

$b_k = x_k - \ell_k m_k$

And now we have a piecewise linear function: $x_f(\ell) = m_k \ell + b_k \text{ for } x_{k-1} \le \ell < x_k$

Now we wish to place $m$ spaces between points, so we take values $\frac{\ell_ni}{m}$ for $i$ in $0 \le i \le m$, find their $x$ values from the piecewise linear function above, and then from there the $f(x)$ values.

Example

Our star today is the standard normal distribution density function, $$f(x) = \frac{1}{\sqrt{2\pi}}e^{-\frac{x^2}{2}}$$

over the interval $-3 \le x \le 3$. I'll use $n = 6$ here for relative brevity and for relatively nice $x$ values.

$x$ $y$ $d$ $\ell$ $m$ $b$ formula interval
$-3$ $0.004432$
$-2$ $0.053991$ $1.001227$ $1.001227$ $0.998774$ $-3.000000$ $0.998774\times \ell -3.000000$ $0.000000\le \ell < 1.001227$
$-1$ $0.241971$ $1.017515$ $2.018742$ $0.982787$ $-2.983993$ $0.982787\times \ell -2.983993$ $1.001227\le \ell < 2.018742$
$0$ $0.398942$ $1.012245$ $3.030987$ $0.987903$ $-2.994322$ $0.987903\times \ell -2.994322$ $2.018742\le \ell < 3.030987$
$1$ $0.241971$ $1.012245$ $4.043232$ $0.987903$ $-2.994322$ $0.987903\times \ell -2.994322$ $3.030987\le \ell < 4.043232$
$2$ $0.053991$ $1.017515$ $5.060747$ $0.982787$ $-2.973635$ $0.982787\times \ell -2.973635$ $4.043232\le \ell < 5.060747$
$3$ $0.004432$ $1.001227$ $6.061974$ $0.998774$ $-3.054544$ $0.998774\times \ell -3.054544$ $5.060747\le \ell < 6.061974$

at this point I want to point something out: the curve length of this function is only about 1% more than the width of our interval in $x$. There isn't going to be much difference between evenly spaced on $x$ and evenly spaced along the curve! In fact when we get our points, the largest difference between the two is about $0.008$. Still, the point here is a reasonably general procedure, so let's continue.

Now that we've got our piecewise linear function, we'll just plug in evenly-spaced $\ell$ values.

$\ell$ $x$ $y$ $\ell$ $x$ $y$
$0.000000$ $-3.000000$ $0.004432$ $3.030987$ $0.000000$ $0.398942$
$0.303099$ $-2.697273$ $0.010498$ $3.334086$ $0.299432$ $0.381453$
$0.606197$ $-2.394546$ $0.022689$ $3.637185$ $0.598864$ $0.333452$
$0.909296$ $-2.091818$ $0.044744$ $3.940283$ $0.898296$ $0.266493$
$1.212395$ $-1.792467$ $0.080026$ $4.243382$ $1.196705$ $0.194954$
$1.515494$ $-1.494586$ $0.130572$ $4.546481$ $1.494586$ $0.130572$
$1.818592$ $-1.196705$ $0.194954$ $4.849579$ $1.792467$ $0.080026$
$2.121691$ $-0.898296$ $0.266493$ $5.152678$ $2.091818$ $0.044744$
$2.424790$ $-0.598864$ $0.333452$ $5.455777$ $2.394546$ $0.022689$
$2.727888$ $-0.299432$ $0.381453$ $5.758876$ $2.697273$ $0.010498$
$6.061974$ $3.000000$ $0.004432$

And we can plot these.

21 points evenly spaced along the normal distribution