14

Let's say I have a vector like this: $⟨-2,7,4⟩$

What's the best way to find a perpendicular vector for this?

Right now I'm doing $-2x+7y+4z=0$

And plugging in random values for $x$, $y$, and $z$ until I get $0$. This can't be right, right?

Si Random
  • 911
  • 7
    Do you know about the cross product? – J. W. Tanner Sep 10 '20 at 20:13
  • @J.W.Tanner yes sir. that find's a perpindicular vector to a plane yea? – Si Random Sep 10 '20 at 20:13
  • There should be an entire $n-1$ dimensional vector space orthogonal to any given $n$ dimensional vector. – CyclotomicField Sep 10 '20 at 20:17
  • 3
    plugging random values works fine, just pick the first two in such a way as it will be easy to solve for the 3rd. e.g. set one of them equal to zero. – Doug M Sep 10 '20 at 20:19
  • wow so many answers, i gotta process em for a bit lol. see which one i like thank you all if ur reading this comment – Si Random Sep 10 '20 at 20:24
  • The equation -2x + 7y + 4z = 0 defines a plane. The intersection of the plane with a unit sphere x^2 + y^2 + z^2 = 1 defines a circle on the plane. Any point on the circle can be used to define a vector perpendicular to {-2, 7, 4}. To solve the intersection of sphere with plane is provided in this StackExchange thread: https://math.stackexchange.com/questions/943383/determine-circle-of-intersection-of-plane-and-sphere – Xavier Sep 11 '20 at 06:21
  • @DougM You should write this as an answer. IMHO it is by far the easiest solution to the OP's problem! – Philipp Imhof Sep 11 '20 at 09:56
  • 5
  • One answer is $\langle0,0,0\rangle$. Another answer is: this is a system of linear equations (just one equation, but still), and so linear algebra will tell you the entire set of solutions; in this case, the answer is that $y$ and $z$ can be arbitrary and $x=\frac72y+2z$. – Greg Martin Sep 12 '20 at 04:34
  • 1
    Plug in random values for $y,z$ and let $x= {1\over 2} (7y+4z)$. – copper.hat Sep 12 '20 at 04:39

7 Answers7

33

You don't need the cross-product, as long as you have a scalar product. Remember, most vector spaces do not have a cross-product, but a lot of them do have a scalar product.

Take any arbitrary vector $\vec{r}$ that is not parallel to the given vector $\vec{v}$.

Then $\vec{q} = \vec{r} - \left(\frac{\vec{r}\cdot\vec{v}}{\vec{v}\cdot\vec{v}}\right) \vec{v}$ will be orthogonal to $\vec{v}$.

To prove this, just show that $\vec{q} \cdot \vec{v} = 0$, which just takes a little bit of algebra.

This process is the basis of the Gram-Schmidt process, an important process in linear algebra.

  • Even if GS process is important, I don't agree that this is the "best way to find a perpendicular vector" given any vector, where for best I mean effective and fast. Of course GS process is in general the best way to orthogonalize a given set of independent vectors without affect their span, but it doesn't seem more efficent than other simple methods to find one perpendicular vector. Moreover if I want create a triple of orthogonal vectors in $\mathbb R^3$, cross product is still a very efficent way to find the third perpendicular vector in the triple. – user Sep 12 '20 at 19:30
  • Hi @Robby the Belgian please can you help with https://math.stackexchange.com/q/4396103/585488 – linker Mar 05 '22 at 15:36
28

To answer a question you didn't ask, one might wonder "Is there a nice formula that consumes a unit vector $v = (a,b,c)$ and produces a unit vector perpendicular to $v$?" (Of course, if you have a way to produce a vector perpendicular to $v$, you can always divide by its length to get a UNIT vector.)

If by "nice formula", you mean "a triple of expressions involving $a,b,c$, each of which is a continuous function", then the answer is (somewhat surprisingly) "no".

Such a formula would provide, for each point of the unit sphere (the endpoint of your vector $v$) a vector $w$ which, translated to the tip of $v$, is tangent to the sphere, i.e., you'd get an everywhere nonzero continuous vector field on the unit sphere.

And such a thing cannot exist by the Morse Index Theorem.

This is one of my favorite examples of a nice simple-sounding question being tied to a deep theorem of topology.

John Hughes
  • 93,729
  • 7
    I agree with this answer, but this hasn't stopped people from coming up with various methods anyway to conveniently generate an orthonormal basis starting from only one given vector, e.g. Hughes-Moller, Frisvad, and Duff et al. of Pixar. – J. M. ain't a mathematician Sep 11 '20 at 07:58
  • 36
    I agree completely. I am, for instance, the "Hughes" of Hughes-Moller. :) – John Hughes Sep 11 '20 at 11:37
  • 1
    I want to make a crack here about "good thing you're not the John Hughes of Pretty in Pink" but I can't make it come out funny. Oh well. Hail and well met, Dr. Hughes. – Ross Presser Sep 11 '20 at 12:36
  • Why must a "formula" necessarily give a "continuous vector field"? – Eric Towers Sep 11 '20 at 12:48
  • The "nice" formulas of, say, Algebra 1, mostly involve continuous functions, and indeed, in my second paragraph I wrote "If by "nice formula", you mean "a triple of expressions involving , each of which is a continuous function", then the answer is (somewhat surprisingly) "no"." If you have a formula that produces discontinuous functions, then this observation of mine has no application to your situation. – John Hughes Sep 11 '20 at 12:56
  • 1
    I thought it was called the Hairy Ball Theorem? Is Morse Index Theorem more general? – Jake Stevens-Haas Sep 11 '20 at 15:50
  • Yes; the hairy ball theorem is a consequence of Morse (which isn't much harder, but is far more general, applying to all surfaces, and indeed, to higher-dimensional manifolds as well). – John Hughes Sep 11 '20 at 16:27
  • If you had a continuous function $f$ such that $v \cdot f(v) = 0$ for every unit vector $v$, then $f$ would be a continuous mapping from the unit sphere to itself that has no fixed points. There are topological theorems that say this is impossible, aren’t there? Brouwer? – bubba Sep 13 '20 at 01:44
  • Sure, something like the Brouwer theorem would almost do that (the Brouwer theorem is for the disk rather than the sphere). But since the antipodal map on $S^2$ gives a map with no fixed points, you need something a little stronger than a Brouwer-like theorem, and Morse provides that. A quick morse-based proof of your Brouwer-like theorem is this: Suppose $f$ is a nonzero map on $S^2$ with no fixed points, and with $f(p) \ne -p$ for any $p$. Then let $g(p) = f(p) - (f(p) \cdot p)p$ is an everywhere nonzero tangent field. Just your "proof" in reverse! – John Hughes Sep 13 '20 at 15:17
18

Given any vector $(a,b,c)$, with $a,b,c\neq 0$, a fast way to find a perpendicular vector is to consider

$$(-b,a,0) \implies (a,b,c)\cdot (-b,a,0) =-ab+ba+0=0$$

or other similar combination of the components as for example $(-c,0,a)$ or $(0,c,-b)$.

When one or two components are equal to zero, find a perpendicular vector is trivial, e.g. $(a,b,0)\perp (0,0,c)$.


If we are interested to find a triple of orthogonal vectors, starting from one given vector, assuming $a,b,c \neq 0$, we can proceed as follows:

  1. The starting vector contains two zero components, the orthogonal triple is

$$v_1=(a,0,0) \quad v_2=0,b,0) \quad v_3=(0,0,c)$$

  1. The starting vector contains one zero components, one orthogonal triple is

$$v_1=(a,b,0) \quad v_2=(-b,a,0) \quad v_3=(0,0,c)$$

  1. The starting vector doesn't contain zero components, one orthogonal triple is

$$v_1=(a,b,c) \quad v_2=(-b,a,0) \quad v_3=v_1 \times v_2 = (-ac,-bc,a^2+b^2)$$

user
  • 154,566
  • "or similar combination" is important, for if $a = b = 0$, then this vector has zero dot-product with your vector, but is probably not what you're looking for. – John Hughes Sep 10 '20 at 20:16
  • @JohnHughes Yes, I'm assuming $a,b,c \neq 0$. I add that. Thanks – user Sep 10 '20 at 20:17
  • You don't really need to add that; you say "If $a \ne 0$, then $(-b, a, 0)$ works. Otherwise one of $b,c$ must be nonzero, or the question makes no sense, and $(0, -c, b)$ works." – John Hughes Sep 10 '20 at 20:21
  • @JohnHughes My point is that if one or two components are equal to zero, find a perpendicular vector is trivial, for that reason I've given an indication for the case with all components $\neq 0$. I add somethign also on that! Thanks – user Sep 10 '20 at 20:24
  • 1
    Ah..good point. I also (with my computer-science hat on) like to mention that if you're going to set one component to zero and swap the other two, negating one, the one to set to zero is usually...the one that's smallest in absolute value. (Probably even better to choose the number $x$ for which $\log(|x|)$ is as large as possible, but I'd have to think more about that...) – John Hughes Sep 10 '20 at 20:29
  • @JohnHughes Floating-point error issue I suppose, but really I'm not an expert on that! Thanks again for the suggestion and nice discussion. Regards – user Sep 10 '20 at 20:36
5

There are many vectors perpendicular to $(-2,7,4)$. One way to find one would be to take the cross product of $(-2,7,4)$ and a vector not parallel to it, such as $(1,0,0)$. The cross product of two vectors is perpendicular to both of them.

J. W. Tanner
  • 60,406
4

If all you want is just any perpendicular vector whatsoever, then the easiest is to just take the zero vector.

If you want any nonzero vector perpendicular to $v=(v_1,v_2,\ldots, v_n)$, then probably the simplest choice is: if $v_1=0$, then take $w=(1,0,\ldots, 0)$. If $v_1\neq 0$, then take $w=(v_2,-v_1,0,0,\ldots,0)$. If your vectors are complex, take $w=(\bar v_2,-\bar v_1,0,\ldots, 0)$ instead.

Works in arbitrary dimension at least $2$ (in dimension $0$ or $1$ there might be no nonzero perpendicular vectors).

tomasz
  • 35,474
2

I’m assuming the given vector is not all zeros. Then the steps are:

Find the component that has the smallest magnitude. Replace it by $0$. Swap the other two components, and change the sign of one of them.

So, if your vector is $(-2,7,4)$, then ... The component with smallest magnitude is $-2$. Replace it by zero, which gives $(0,7,4)$. Swap the $7$ and the $4$. This gives $(0,4,7)$. Negate the $7$, which gives $(0,4,-7)$.

Check: $(-2,7,4) \cdot (0,4,-7)=0$.

This is essentially the same process given in another answer, but it’s described in a different way that some people might find easier to understand.

Picking the smallest component to zero out is not absolutely necessary, but if you’re writing computer code, you have to make some definite choice, and this choice always works for non-zero vectors.

bubba
  • 43,483
  • 3
  • 61
  • 122
  • 3
    And if your vector is $(0,7,0)$, the largest component is $7$, replace it by zero and swap and negate the other two to get $(0,0,0)$! There is no reason to pick the largest magnitude to zero out. Picking the smallest magnitude instead ensures your result will be non-zero unless the original vector was zero itself. But this is essentially the same method that user had already posted. – Paul Sinclair Sep 11 '20 at 16:14
  • 1
    Yes, smallest, not largest. Fixed. Thank you. – bubba Sep 11 '20 at 22:30
2

And plugging in random values for x, y, and z until I get 0. This can't be right, right?

You have a linear equation. You can solve it using any of the methods that exist for solving systems of linear equations. For instance, since you have three variables and one equation, there are two degrees of freedom for the solution space. You can pick any two variables as free variables and solve the third in terms of those two. For instance, if you choose $x$ and $y$ as the free variables, then you have $4z = 2x-7y$, or $z = \frac x 2-\frac {7y}4$. This tells you that you can pick any values for $x$ and $y$ to get a solution. For instance, if $x = 10$, $y = 4$, then $z= 3$, giving the vector $(10, 4, 3)$. So you can plug in random values for two of the varaibles, and get the third using math.

Acccumulation
  • 12,210