# Generalised change of spherical coordinates

I have a set of points in an equatorial coordinate system specified by a longitude, $0^{\circ}\leq\alpha < 360^{\circ}$ and a latitude, $-90^{\circ}\leq \delta \leq +90^{\circ}$

I want to take a point with coordinates $(\alpha_1,\delta_1)$ and create a second coordinate system such that my point now has coordinates $(\alpha_2,\delta_2)$. I then want to apply that transformation to every point in the set.

Shifting in longitude with constant latitude is straightforward, the transformation is just $(\alpha,\delta)\rightarrow(\alpha+\alpha_2-\alpha_1,\delta)$, but shifting in latitude is more complicated due to behaviour around the poles.

There's a similar question here that rotates the equator of the coordinate system to intersect with the point while preserving the points longitude (i.e. shifting latitude with constant longitude). There is definitely a way to generalise the top answer to that question so that it solves my problem, I just can't seem to figure it out.

I can imagine a series of transformations such that I shift $(\alpha_1,\delta_1)$ to $(0,\delta_1)$ using the longtitude transformation I mention above, then use the solution to the other question to shift that to $(0,0)$, then use an inverse transformation to shift it to $(0,\delta_2)$ and then finally a simple longitude transformation to shift it to $(\alpha_2,\delta_2)$.

However, that sounds like an overly complicated solution.

There should (hopefully!) be a way to do it with a single coordinate transformation, which would be preferable since I have to write this in Python and more transformations means more compute time. I'll be calculating and applying this transformation ~10,000 times to approximately 10 million points, so needlessly increasing the number of calculations has big flow-on effects.

• I would step back and examine why you want to do this. I think the question you linked to made assumptions that made the problem harder; perhaps you are doing that too. – David K Jul 26 '18 at 3:01

The sequence of transformations you describe is one good way to solve the problem, by representing the rotation as the product of three rotations about coordinate axes. You can also construct a single rotation directly if you prefer. There's a continuum of rotations that transform a given point into a given other point; any axis that's equidistant from the two points will do. The two ends of this continuum are easier to construct than the rest. Transform the points to vectors in Cartesian coordinates. To rotate through the least possible angle, take the cross product as the axis and the angle between the vectors as the angle. To rotate through the greatest possible angle, take the midpoint (half the sum) as the axis and $\pi$ as the angle. See Rodrigues' rotation formula on how to build a rotation matrix given an axis and an angle.