- #1

clandarkfire

- 31

- 0

I'm running a galaxy formation simulation. The output specifies the coordinates in (x, y, z) of all the particles in a galaxy, which usually fall in a disk. The orientation of the disk depends on the initial conditions, but it is generally not aligned with any of the coordinate axes.

I'm trying to write a function that will allow me to view the disk face on, rather than along one of the coordinate axes. E.g., I can view the galaxy along the z-axis by plotting x vs y for all particles, but unless the galaxy is in the x-y plane, I look at it at some arbitrary angle.

Right now, I'm finding the moment of inertia tensor of all the particles in the galaxy and using this to find the principal axes. As I would expect, the principal axis corresponding the the largest eigenvalue (e.g., moment) is a vector perpendicular to the disk.

Now I would like to "view" the galaxy looking along this principal axis. That is, I want to rotate my coordinate axes so that the z' axis is aligned with the principal axis. This will give all my particles new coordinates (x', y', and z'), and plotting (x' vs y') should show the disk face-on.

I know how to do this transformation using rotation matrices in terms of the angles α, β, and γ that I rotate around the x, y, and z axes, or in terms of the Euler angles. But for the life of me, I can't figure out how to properly find these angles if I want the z' axis to be aligned with the principal axis, say v = (v_x, v_y, v_z). My original thought was to set α=0 and then set β to the polar angle, given by β=v_z/sqrt(v_x^2 + v_y^2 + v_z^2). Finally, I'd set γ to the azimuthal angle.

This works if v is in the x-y, x-z, or y-z planes. But for an arbitrary v, it doesn't, because these rotations don't commute.

So how can I find α, β, and γ such that z' will align with an arbitrary v?

Thanks so much!