I’m writing a simple 2d brownian motion simulator in Python. It’s obviously easy to draw values for x displacement and y displacement from a distribution, but I have to set it up so that the 2d displacement (ie hypotenuse) is drawn from a distribution, and then translate this to new x and y coordinates. This is probably trivial and I’m just too far removed from trigonometry to remember how to do it correctly. Am I going to need to generate a value for the hypotenuse and then translate it into x and y displacements with sin and cos? (How do you do this correctly?)
I’m writing a simple 2d brownian motion simulator in Python. It’s obviously easy to
Share
This is best done by using polar coordinates
(r, theta)for your distributions (whereris your “hypotenuse”)), and then converting the result to(x, y), usingx = r cos(theta)andy = r sin(theta). That is, selectrfrom whatever distribution you like, and then select atheta, usually from a flat, 0 to 360 deg, distribution, and then convert these values toxandy.Going the other way around (i.e., constructing correlated (x, y) distributions that gave a direction independent hypotenuse) would be very difficult.