# Calculate 3D vector perpendicular to a plane generated by two vectors

I am new to dealing with 3D, and even simple stuff makes my head spin around. Sorry for the newbie question.

Lets say I have 2 vectors:

``````a(2,5,1)
b(1,-1,3)
``````

These vectors "generate" a plane. How can I get a third vector perpendicular to both a and b?

I can do this in 2D using a vector c(A,B) and turning it into c'(-B,A).

Thanks for the help.

-

Use the cross product.

That is, a vector perpendicular to `a` and `b` is given by `( a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x)`.

-

You take the cross multiplication of these two vectors to get a third perpendicular vector to the plane they generate:

``````P = A * B
``````

Which is:

``````<xp, yp, zp> = |i   j   k |
|xa  ya  za| // The determinant
|xb  yb  zb|
``````

All what you have to do is to solve this determinant or just look it up in Wikipedia :)

-
I like this answer better because it explains where the answer comes from. Not just a random formula to remember. –  Robert Massaioli Oct 19 '09 at 23:52
Thanks, I would accept this too : ) –  nonammeN Oct 20 '09 at 0:00
``````void CrossProduct( const vec3_t v1, const vec3_t v2, vec3_t cross ) {
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}