# Transforming regular lat/lon to rotated lat/lon?

I am currently working with climate data projected in a rotated lat/lon grid and came across this excellent 'cookbook' by @mkadunc on Manually transforming rotated lat/lon to regular lat/lon?

I’ve implemented the solution for transforming a rotated grid to a regular grid; however, I’m also interested in doing the opposite. My first thought was to just change the operational sign of ϑ and φ, so that the transformation will go ‘the other way around the clock’, but this doesn’t seem to work leaving me a bit stuck here. I’ve spend some hours now trying to read up on my trigonometry, but still haven’t been able to ‘reverse’ the function.

• No trig is needed: just invert the matrix for the (x',y',z') -> (x,y,z) transformation. Jun 24, 2013 at 16:54

I finally got there myself with help from @whuber. While @mkadunc shows how to ‘undo’ a rotation, where the rotated coordinate system is first rotated around the y'-axis and then the z'-axis to match a regular coordinate system, I was interested in performing a rotation from a regular grid; thus, the regular coordinate system shall first be rotated around the z-axis and then the y-axis.

Hence, when you calculate the product of:

``````x   ( cos(φ), sin(φ), 0) (  cos(ϑ), 0, sin(ϑ)) (x')
y = (-sin(φ), cos(φ), 0).(  0     , 1, 0     ).(y')
z   ( 0     , 0     , 1) ( -sin(ϑ), 0, cos(ϑ)) (z')
``````

where the first matrix (A) represent the rotation around the z-axis and the second matrix (B) represent the rotation around the y-axis, A*B becomes:

``````x   ( cos(ϑ)cos(φ) , -cos(ϑ)sin(φ) , -sin(ϑ)) (x')
y = ( sin(φ)       ,  cos(φ)       ,  0     ).(y')
z   ( sin(ϑ) cos(φ), -sin(ϑ) sin(φ),  cos(ϑ)) (z')
``````

which is indeed the inverse of BA, or (BA)^T since it's orthogonal.

In case anyone is interested I've shared a MATLAB script on the file exchange transforming regular lat/lon to rotated lat/lon and vice versa: Rotated grid transform