Calculate a three-dimensional vector perpendicular to the plane generated by two vectors

I'm new to 3D, and even simple things make my head spin. Sorry for the newbie question.

Suppose 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 the vector c (A, B) and turning it into c '(- B, A).

Thanks for the help.

+3
source share
3 answers

Use a cross product .

, , a b, ( a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x).

+14

, , :

P = A * B

:

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

, , - Wikipedia:)

+7

For what it's worth, the product cross-function from Quake 3, with vec3_t, defined as an array of three floats for x, y and z:

void CrossProduct( const vec3_t v1, const vec3_t v2, vec3_t cross ) {
    cross[0] = v1[1]*v2[2] - v1[2]*v2[1];
    cross[1] = v1[2]*v2[0] - v1[0]*v2[2];
    cross[2] = v1[0]*v2[1] - v1[1]*v2[0];
}
+2
source

Source: https://habr.com/ru/post/1720519/


All Articles