Python Forum

Full Version: Rotate 2D Gaussian given parameters
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a Gaussian function of the form:

def f(x,y):
  a=some number
  b=...
  c=...
  return 3*np.exp(-a*(-0.5 + x)**2+b*(x-0.5)*(y-0.5)-c*(-0.5 + y)**2)
This is a Gaussian function symmetric around y=x, and I'd like to rotate it 45 degrees (counter)clockwise. Wikipedia gives an overdetermined system of equations for the variances of x and y respectively, but it looks cumbersome. Is there a simple way to do this?

Gaussian parameters
Can't you make use of a rotation matrix? For each point (x, y) the rotation matrix would give you new points (x', y') and then you simply compute f at those new points.
(Dec-10-2020, 06:37 PM)ndc85430 Wrote: [ -> ]Can't you make use of a rotation matrix? For each point (x, y) the rotation matrix would give you new points (x', y') and then you simply compute f at those new points.

True. So then one would probably first need to normalize f. How would one then generate the points (x,y) using f as a density?
(Dec-10-2020, 06:44 PM)schniefen Wrote: [ -> ]
(Dec-10-2020, 06:37 PM)ndc85430 Wrote: [ -> ]Can't you make use of a rotation matrix? For each point (x, y) the rotation matrix would give you new points (x', y') and then you simply compute f at those new points.

True. So then one would probably first need to normalize f. How would one then generate the points (x,y) using f as a density?

I would like to find the new parameters a,b and c of the rotated version as well.
A rotation by 45 degrees, with the means (0.5,0.5) fixed, gives a’=(a-b+c)/2, b’=a-c=0 and c’=(a+b+c)/2 for a counterclockwise rotation and a’=(a+b+c)/2, b’=a-c=0 and c’=(a-b+c)/2 for a clockwise rotation.