Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Converting a 2D Gaussian in Cylindrical Coordinates

  1. May 20, 2015 #1
    Given the equation for a Gaussian as: ##z = f(x,y) = Ae^{[(x-x0)^2 + (y-y0)^2] /2pi*σ^2 }## , how would I go about converting this into cylindrical coordinates? The mean is non-zero, and this seems to be the biggest hurdle. I believe I read earlier that the answer is ~ ##z = f(r,θ) = Ae^{(r-r0)^2 / σ^2}## but this doesnt quite make sense since it completely neglects the angle (i.e. theta). Would this be the correct solution?

    ## x = rcosθ##;
    ##y = rsinθ##;
    ##x0 = r0cosθ0##;
    ##y0 = r0sinθ0##; where ##r0## and ##θ0## and ##σ## are constants

    ##z = f(r,θ) = Ae^{(r^2 + r0^2 - 2rcosθr0cosθ0 - 2rsinθr0sinθ0 / σ^2 }##

    This is just a direct substitution, though. Shouldn't there be a change of variable and thus making the solution:

    ##z = f(r,θ) = rAe^{(r^2 + r0^2 - 2rcosθr0cosθ0 - 2rsinθr0sinθ0 /σ^2 }##

    Any advice?
    Last edited: May 20, 2015
  2. jcsd
  3. May 20, 2015 #2


    Staff: Mentor

    I believe that it would be helpful to change your variables, with u = x - x0, and v = y - y0. Then you would have ##z = f(u, v) = Ae^{\frac{u^2 + v^2}{2\pi \sigma^2}}##
    It should be relatively easy to change to cylindrical coordinates in this form.

    Not all functions in cylindrical (or polar) coordinates involve an angle. For example, in polar coordinates, the equation of a circle of radius r0, and centered at the pole is r = r0. Here ##\theta## is arbitrary. This equation also represents a circular cylinder in cylinder in cylindrical coordinates, with both ##\theta## and z being arbitrary.
  4. May 20, 2015 #3
    Is it most accurate to leave just as:

    ## f(r,θ) = A1e^{(r^2 + r0^2 - 2rcosθr0cosθ0 - 2rsinθr0sinθ0 /σ^2) }rdrdθ = f(x,y) = Ae^{[(x-x0)^2 + (y-y0)^2] /σ^2] }dxdy##

    I guess I'm just confused on how exactly I would graph the function.

    (Should the denominator in the exponential be 2pi*σ^2 for both cases instead of just σ^2 for ny particular reason? I believe I've seen that convention but have not seen an explanation as for why.)
    Last edited: May 20, 2015
  5. May 20, 2015 #4
    The only problem with this method (I left out this piece of information) is that I would want to graph this function on the same set of axes for numerous values of x0 and y0 (or r0 and theta0). That is, these values would be constant for any given situation, but I would like to generalize this function so that these constants can take on any arbitrary value when I graph them in the future, but remain on the same set of axes. For example, my mean position for the gaussian could be r0 = 2, theta0 = 0.5 for one run, but it would r0 = 2.5, theta0 = 0.8 for another run.
  6. May 20, 2015 #5


    Staff: Mentor

    All that's happening with the substitutions I listed is that the origin in the x-y plane is translated to the point (x0, y0), which is the origin in the u-v plane. Different values of x0 and y0 simply move the location of the origin in the u-v plane.
  7. May 20, 2015 #6
    Okay. This would then change the function itself, no? Essentially what's being done is that I have a function, and I input these constants before running them to get the plot. Wouldn't this substitution then have to be applied for each function? It definitely seems like the sensible approach, but I'm not quite sure if its application would work when I'm trying to input different values and trying to get the functions displayed on the same graph.
    Last edited: May 20, 2015
  8. May 20, 2015 #7


    Staff: Mentor

    Yes, but all you would be doing is translating one coordinate system rigidly so that the new origin is at a different point. As a simpler example, if you know what the graph of y = f(x) = sin(x) looks like, the graph of f(x - ##\pi/4##) is nothing more than a translation to the right of the graph of sin(x) by ##\pi/4## units.

    The situation is similar in the substitutions I recommended, except that there would be two translations.
    To go back to your original equation, ##z = f(x,y) = Ae^{\frac{(x - x_0)^2 + (y - y_0)^2}{2\pi*σ^2} }##, and disregarding the thing about switching to cylindrical coordinates, the graph of this surface looks just like the graph of ##z = e^{\frac{x^2 + y^2}{2\pi*σ^2}}##, but with the high point of the mound translated so that it's above (x0, y0) instead of being above (0, 0). If you change the value of either x0 or y0 (or both), it simply moves the high point around.

    It's not clear to me what you're trying to do: change the equation to cylindrical form or graph the family of surfaces with different values of x0 and y0. These seem like different goals to me.
  9. May 21, 2015 #8
    Thank you. Yes, the two graphs should look the same, regardless of the coordinates. I guess I'm trying to verify if my steps are correct or not. I've inserted an image file with this that explains the function itself and what I did to convert it. I can now integrate over this function, correct? Integration over that circle would be correct using the equations found for z either in cartesian or polar coordinates, correct?

    I guess my main question is due to lack of familiarity and being unable to plot both graphs. Would the two functions of z, the one in dxdy and the other in rdrdtheta be the same if i removed ONLY dxdy and drdtheta from both of them? If I'm not mistaken, it should simply be multipled by the Jacobian (i.e. r x drdtheta/dxdy) to achieve the same function back. That is, since I have z1dxdy (original cartesian function) = z2rdrdtheta (polar), shouldnt it be z1 = rz2 x drdtheta/dxdy? Where z1 is in x and y and z2 is simply the same function but with x and y directly subsituted with the appropriate rcostheta and rsintheta change.

    Attached Files:

  10. May 21, 2015 #9


    User Avatar
    Gold Member

    You want to send the coordinates to polar?
    [itex] e^{\frac{(x-x_0)^2}{2\sigma^2}} e^{\frac{(y-y_0)^2}{2\sigma^2}}[/itex] ?

    One way to achieve this before you go to polar coordinates, to make a small transposition to your axis. In explicitly say that you move your [itex]x[/itex] axis by [itex]x_0[/itex] to : [itex]x \rightarrow x'= x -x_0[/itex] and your [itex]y[/itex] axis by [itex]y_0[/itex] to : [itex]y \rightarrow y'= y-y_0[/itex].
    After doing that you have:
    [itex]e^{\frac{x^{\prime 2}}{2\sigma^2}} e^{\frac{y^{\prime 2}}{2\sigma^2}} [/itex]

    [itex]e^{\frac{x^{\prime 2} + y^{\prime 2}}{2\sigma^2}}[/itex]

    Which immediately can be written in polar coordinates as:

    [itex]e^{- \frac{r^2}{2 \pi \sigma^2} } [/itex]

    Where [itex]r^2 = x^{\prime 2} + y^{\prime 2} = (x-x_0)^2 + (y-y_0)^2 [/itex]
    That's a circle equation, with radius [itex]r[/itex] and center at [itex] (x_0 ,y_0 )[/itex]

    Now if you want to integrate it, you can do it either in x,y or in r,theta....
  11. May 22, 2015 #10
    Yep, that definitely makes sense. I'm just trying to get the analytical solution for the Gaussian if it is not centred at [itex] (x_0 ,y_0 )[/itex] but still in polar coordinates (i.e. the coordinate system is centred at the origin).

    I think I've been a little unclear (possibly an understatement) in what I've asked above so hopefully I can try to clarify what exactly it is I'm trying to do.
    This is the solution I've got so far to plot:

    (see attached image file)

    My questions are stated in the image, but to state them again:

    Is ##z_{xy}## equivalent to ##z_{rθ}## when plotted in Cartesian and Cylindrical coordinates, respectively? Also, when integrating over equivalent surfaces (e.g. r: [0,4] and θ: [0,2pi] in cylindrical coordinates or a circle of radius 4 centred at the origin in cartesian coordinates), is dxdy simply replaced by rdrdθ for ##z_{rθ}## or are there additional substitutions I am missing?

    What I'm trying to do doesn't seem too difficult so sorry if I overcomplicated a simple problem. I actually have been plotting the graphs now and it does seem to be working, but I just want to confirm my methods are correct.

    Attached Files:

    Last edited: May 22, 2015
  12. May 22, 2015 #11


    User Avatar
    Gold Member

    What do you mean by asking whether the [itex]z_{r\theta} , z_{xy}[/itex] are equivalent? They are the same thing expressed in different coordinates...
    Whether I write [itex]f(x,y)=x^2+y^2[/itex] or [itex]f(r,\theta)=r^2[/itex] with [itex]r^2=x^2+y^2[/itex], it's the same thing.

    Then about the integration. It's still fine. You have been able to write the integrand function in different coordinates, and you also need to transform (through the jacobian) the integral's measure [itex]dxdy[/itex] which is done by [itex]rdr d\theta[/itex]. Where would the additional substitutions come from? (equivalent question, what is confusing you?)
  13. May 22, 2015 #12
    I guess I was just looking for confirmation that what I did was right. It really is simple but I thought it never hurts to ask. Thank you! :)
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook