14
$\begingroup$

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?

$\endgroup$
10
  • 7
    $\begingroup$ Do you know about the cross product? $\endgroup$ Sep 10, 2020 at 20:13
  • $\begingroup$ @J.W.Tanner yes sir. that find's a perpindicular vector to a plane yea? $\endgroup$
    – Si Random
    Sep 10, 2020 at 20:13
  • 3
    $\begingroup$ 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. $\endgroup$
    – Doug M
    Sep 10, 2020 at 20:19
  • 5
    $\begingroup$ Does this answer your question? How to find perpendicular vector to another vector? $\endgroup$
    – KingLogic
    Sep 12, 2020 at 0:00
  • 1
    $\begingroup$ Plug in random values for $y,z$ and let $x= {1\over 2} (7y+4z)$. $\endgroup$
    – copper.hat
    Sep 12, 2020 at 4:39

7 Answers 7

33
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ 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. $\endgroup$
    – user
    Sep 12, 2020 at 19:30
  • $\begingroup$ Hi @Robby the Belgian please can you help with math.stackexchange.com/q/4396103/585488 $\endgroup$
    – LiNKeR
    Mar 5, 2022 at 15:36
27
$\begingroup$

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.

$\endgroup$
9
  • 7
    $\begingroup$ 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. $\endgroup$ Sep 11, 2020 at 7:58
  • 35
    $\begingroup$ I agree completely. I am, for instance, the "Hughes" of Hughes-Moller. :) $\endgroup$ Sep 11, 2020 at 11:37
  • 1
    $\begingroup$ 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. $\endgroup$ Sep 11, 2020 at 12:36
  • $\begingroup$ Why must a "formula" necessarily give a "continuous vector field"? $\endgroup$ Sep 11, 2020 at 12:48
  • 1
    $\begingroup$ I thought it was called the Hairy Ball Theorem? Is Morse Index Theorem more general? $\endgroup$ Sep 11, 2020 at 15:50
18
$\begingroup$

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)$$

$\endgroup$
6
  • $\begingroup$ "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. $\endgroup$ Sep 10, 2020 at 20:16
  • $\begingroup$ @JohnHughes Yes, I'm assuming $a,b,c \neq 0$. I add that. Thanks $\endgroup$
    – user
    Sep 10, 2020 at 20:17
  • $\begingroup$ 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." $\endgroup$ Sep 10, 2020 at 20:21
  • $\begingroup$ @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 $\endgroup$
    – user
    Sep 10, 2020 at 20:24
  • 1
    $\begingroup$ 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...) $\endgroup$ Sep 10, 2020 at 20:29
5
$\begingroup$

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.

$\endgroup$
4
$\begingroup$

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).

$\endgroup$
2
$\begingroup$

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.

$\endgroup$
2
  • 3
    $\begingroup$ 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. $\endgroup$ Sep 11, 2020 at 16:14
  • 1
    $\begingroup$ Yes, smallest, not largest. Fixed. Thank you. $\endgroup$
    – bubba
    Sep 11, 2020 at 22:30
2
$\begingroup$

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.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged .