0
$\begingroup$

I have three 3D vectors. Two of them define an (imaginary) plane (the green and red arrow in the picture). The third vector (the darker blue) can point anywhere it wants. All them have the same origin (lets say [0, 0, 0]) and the same length (say |1|).

How to get a vector that is the (shortest) projection of the dark blue one on that plane (in the image the lighter blue one) and should have the same length afterwards? It must also work when the dark blue vector stands perpendicular on the plane.

project to plane

$\endgroup$
2
$\begingroup$

Let $a_1$ and $a_2$ be the two vectors which form your plane, and $\nu$ be the vector you want to project. Assuming that they all have length 1, the projection will be $$ \nu_{\text{proj}} = a_1(a_1\cdot \nu) + a_2(a_2\cdot \nu) $$ If you want that $\nu_{\text{proj}}$ has the same length then $\nu$, just multiply by $^{\mid \nu \mid}/_{\mid \nu_{ \text{proj}} \mid}$

$\endgroup$
  • $\begingroup$ Thanks for your answer! Unfortunately this won't work when all three vectors a perpendicular to each other (e.g. a1 = [1,0,0]; a2 = [0,1,0]; v = [0,0,1]). The dot product will get 0 and the projection vector will also be [0,0,0]. Is there a trivial way to fix this? $\endgroup$ – Zardoz Aug 5 '16 at 20:34
  • 1
    $\begingroup$ In that case, the third vector is perpendicular to the plane and the zero vector is the right answer, just like you calculate. $\endgroup$ – bob.sacamento Aug 5 '16 at 20:41
  • $\begingroup$ You are right, makes sense. $\endgroup$ – Zardoz Aug 5 '16 at 20:57
  • $\begingroup$ If $a_1 = [1,0,0] ~;~ a_2 = [0,1,0] ~;~ \nu = [0,0,1] $, then $\nu_{\text{proj}} = [1,0,0]$ and $\nu_{\text{proj}} = [0,1,0]$ would both be fine anwers (they are shortest projections with length 1), but every vector $ \nu_{\text{proj}} = [\cos\varphi ,sin\varphi ,0]$ will aslo be fine. Since there is no preference in taking one over the other, the best anwer is to stick with 0 in this case. $\endgroup$ – Nemo Aug 6 '16 at 4:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.