I'm trying to randomly generate coordinate transformations for a fitting routine I'm writing in python. I want to rotate my data (a bunch of $(x,y,z)$ coordinates) about the origin, ideally using a bunch of randomly generated normal vectors ($(a,b,c)$ for a plane given by $ax+by+cz+d=0$). The goal is to shift each plane I've defined so that it lies in the {$z=0$} plane.
How do I get the right transformation matrix from my normal vector? I'm pretty sure I need to start by calculating the angle between the randomly generated normal vector and the one that corresponds to the {$z=0$} plane, $(1,1,0)$. But I have no idea what to do from there.
Rotations will not in general suffice to map the plane $ax+by+cz+d=0$ onto the plane $z=0$, you will almost always need a translation as well. So translate along the normal until you have a plane of the form $ax+by+cz=0$.
If your normal vector is not already parallel to the $z$ axis, the most natural rotation to make it parallel to the $z$ axis is a rotation around an axis in the $xy$ plane that is perpendicular to the normal. Let the normal be $\vec{v}=(a,b,c)$. We seek an axis $\vec{u}=(u_1,u_2,0)$ such that $$\vec{v}\cdot\vec{u}=0$$ $$u_1 a+u_2 b=0$$ Once you found this axis (which is in fact the vector $\mathbf{u}_1$ from amd's answer), you can construct a rotation matrix around this axis $\vec{u}$, and rotate by the angle between $\vec{v}$ and the $z$ axis, which will map your plane onto the $z=0$ plane.