TITLE: How to find the "most upright" orthogonal vector to another vector?
QUESTION [6 upvotes]: Given an arbitrary vector, I can find any orthogonal vector by solving $ax + by + cz = 0$. 
I want to find the "most upright" orthogonal (unit) vector, where $z$ is maximized. There must be a straightforward closed form solution to this, right?

REPLY [12 votes]: Using the observation made by dtldarek in his answer, you’re looking for the unit vector in the plane generated by $w=(a,b,c)$ and $e_3=(0,0,1)$ that is perpendicular to $w$ and has a non-negative $z$-coordinate. Observe that such a vector is also perpendicular to $e_3\times w$, so the vector you seek is $w\times(e_3\times w)$, normalized.