Algorithmic approach to finding two vectors that span a plane I am working on an experiment where I need to align a magnetic field to be parallel to a nanoscale wire embedden in a microscale planar structure. My tools for doing so are two-fold: the planar structure produces a signal $S_P$ (a resonance frequency) that is maximal when the field is fully in plane and that drops off in a typical angle-dependence fashion when not in plane; this dependence smooth and monotonic and essentially noise free, but the visibility quickly reduces when out of plane as the frequency moves out of our measurement window. Similarly (but subject to more stringent conditions) I have a signal $S_W$ produced by the wire that is maximal when the field is in the plane of the planar structure and parallel to the wire; also a resonance frequency. It quickly goes down in an angular fashion both w.r.t. the in-plane angle and the out-of-plane angle. My task is then, with these tools in hand, to align the magnetic field parallel to the wire.
Given that the field is homogeneous over scales much larger than the structures, I believe one can reduce this problem to a more general problem of aligning a 3D vector with spherical coordinates $\vec{v} = (r, \phi, \theta)$ (red) to be parallel to a 1D line (blue) that lies in a 2D plane with unknown vector span (green), at some unknown angle $\xi$ w.r.t. that plane. 

To do this alignment, I had the following idea. In spherical coordinates I can 'algorithmically' control $\phi$ and $\theta$ of the (red) magnetic field vector while monitoring $S_P$, to find two vectors that span the plane. I use these two vectors to set up a new polar coordinate system of that plane, in which I can then sweep the polar angle to find $\xi$ and maximize $S_W$. The second part should be trivial, but the first part is what my question is about. How do I find two vectors that span the plane, controlling $\phi$ and $\theta$ and monitoring $S_P$? 
As it currently stands I can rather easily find a single vector that works by simply varying $\phi$ and $\theta$ until $S_P$ reaches a maximum in both parameters simultaneously, but how do I go from there to find a linearly independent vector that is also in the plane? How should I algorithmically 'walk' through $\phi,\theta$ space to find that other vector? I say walk because what I envision the method to be like is that I start from the local maximum, 'overrotate' in $\theta$, bring $S_P$ back up with $\phi$ and overrotate, that one a bit, and then go back to theta and repeat. That will walk me through the angle space, but how I use this to find the second vector I am not sure of.
Context
Since this is a place where we discuss physics, it might be interesting to give some context. We are working on a 'gatemon' type device (see https://arxiv.org/abs/1503.08339) which is essentially a transmon qubit with a semiconducting nanowire as the junction, and proximity-effect-induced superconducting islands made out of semiconductor segments with superconductor shells. It has a charging energy and a josephson energy and thus a resonance frequency $S_W$, and we couple it to a planar waveguide with resonance frequency $S_P$. We're interested in studying its properties in a magnetic field, but it needs to be in the plane of the waveguide to keep that superconducting, and parallel to the wire to keep that superconducting. So I'm working on a good way to get that alignment as precise as possible.
 A: The line that you're searching is perpendicular to the vector $ \vec v $. If $ \pi $ is a plane normal to $ \vec v $, this line, say $ R $ is inside $ \pi $. You know that this line is in another plane. So the straight line that you are searching is the intersection of this two planes.
The vectors in the plane normal to $ \vec v $ follow the equation:
$$ \vec x  \cdot \vec v = 0 $$
The vectors in the other plane follow the equation:
$$ \vec x \cdot \vec n = 0 $$
We can find the direction of the straight line performing the cross product of the two vectors:
$$ \vec d = \vec { n } \times  \vec { v } $$
Using a point $ \vec a $ that lies in the two planes, the equation of your line is:
$$ \bbox[5px,border:2px solid red] 
{
\vec x = \vec a + t \vec d } $$
A: Consider the following picture:

Green is an arbitrary plane through the origin (corresponding to the plane in the picture of the question), red the xz plane and blue the xy plane. Angles are also taken from there.
If you set $\phi=0$ and sweep $\theta$ clockwise, you'll get a maximum of $S_p$ if you reach the black arrow. 
Likewise, for $\theta=90^\circ$, $S_p$ will be maximal if $\phi$ describes the yellow arrow.
Both arrows define the plane (except for corner cases when the green plane is one of the coordinate planes).
Why do you think this doesn't work?
