user6682440
user6682440

Reputation: 35

How to calculate an orthogonal plane from a vector

I have a position in space called X1. X1 has a velocity called V1. I need to construct an orthogonal plane perpendicular to the velocity vector. The origin of the plane is X1.

I need to turn the two edges from the plane into two vectors, E1 and E2. The edges connect at the origin. So the three vectors form an axis.

I'm using the GLM library for the vector mathematics.

Upvotes: 0

Views: 2202

Answers (2)

dmuir
dmuir

Reputation: 4431

One way to create a frame from a vector is to use Householder transformations. This may seem complicated but the code is in quite short, at least as efficient as using cross products, and less prone to rounding error. Moreover exactly the same idea works in any number of dimensions.

The ideas is, given a vector v, find a Householder transformation that maps v to a multiple of (1,0,0), and then apply the inverse of this to (0,1,0) and (0,0,1) to get the other frame vectors. Since a Householder transformation is it's own inverse, and since they are simple to apply, the resulting code is fairly efficient. Below is C code that I use:

static  void    make_frame( const double* v, double* f)
{
double  lv = hypot( hypot( v[0], v[1]), v[2]);  // length of v
double  s = v[0] > 0.0 ? -1.0 : 1.0;
double  h[3] = { v[0] - s*lv, v[1], v[2]};  // householder vector for Q
double  a = 1.0/(lv*(lv + fabs( v[0])));    // == 2/(h'*h)
double  b;
    // first frame vector is v normalised
    b = 1.0/lv;
    f[3*0+0] = b*v[0]; f[3*0+1] = b*v[1];   f[3*0+2] = b*v[2];

    // compute other frame vectors by applying Q to (0,1,0) and (0,0,1)
    b = -v[1]*a;
    f[3*1+0] = b*h[0]; f[3*1+1] = 1.0 + b*h[1]; f[3*1+2] = b*h[2];

    b = -v[2]*a;
    f[3*2+0] = h[0]*b; f[3*2+1] = b*h[1];       f[3*2+2] = 1.0 + b*h[2];
}

Upvotes: 1

ivan
ivan

Reputation: 348

In general you can define a plane in 3D using four numbers, e.g., Ax+By+Cz=D. You can think of the triple of numbers (A,B,C) as a vector that sticks out perpendicularly to the plane (called the normal vector).

The normal vector n = (A,B,C) only defines the orientation of the plane, so depending on the choice of the constant D you get planes at different distance from the origin.

If I understand your question correctly, the plane you're looking for has normal vector (A,B,C) = V1 and the constant D is obtained using the dot product: D = (A,B,C) . X1, i.e., D = AX1.x + BX1.y + C*X1.z.

Note you can also obtain the same result using the geometric equation of a plane n . ((x,y,z) - p0) = 0, where p0 is some point on the plane, which in your case is V1 . ( (x,y,z) - X1) = 0.

Upvotes: 0

Related Questions