0

I want to generate a Brownina motion smothed by Bézier curve. I have no problem with the first part:

import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm

def brownian(steps):
    r = norm.rvs(size=(2,) + (steps,))
    out = np.empty((2,steps))
    np.cumsum(r, axis=-1, out=out)
    out += np.expand_dims([0,0], axis=-1)
    return out[0], out[1]

x, y = brownian(30)
plt.plot(x, y)

enter image description here

But how can I smooth that path using Bézier curve ?

koryakinp
  • 3,989
  • 6
  • 26
  • 56

2 Answers2

1

I'm not sure you actually want to use a bezier curve, as bezier curves don't go through all of their points (see the Wikipedia explanation - even in a quadratic curve we don't go through the middle point which is just a "guide"). See more information here.

You can however use some math to create a bezier curve that smoothly moves through all of your points. To do that, you'll need some math to figure out where to place the "guides", and then you can draw the actual bezier curve using the bezier drawing code in matplotlib.

If you are fine just with any smooth interpolation and not just bezier curves, then scipy already has some code to do that.

Barak Itkin
  • 4,872
  • 1
  • 22
  • 29
1

You can use Catmull-Rom spline to create multiple cubic Bezier curves that will interpolate the vertices in your walk path and these Bezier curves will be joined smoothly together. Please refer to this link for more details.

fang
  • 3,473
  • 1
  • 13
  • 19