Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Given vector of one axis, how do I find vectors of other two axes?

This is a maths problem I am not exactly sure how to do. The vector is not aligned to an axis, so just rotating 90 degrees around x, y or z won't necessarily give me the other axes.

like image 701
Stoff81 Avatar asked Jun 15 '10 22:06

Stoff81


1 Answers

I can think of a couple of different scenarios you might be asking about.


Given: A pre-existing coordinate system

  • In a 2D system, your axes/basis are always [1,0] and [0,1] -- x and y axes.

  • In a 3D system, your axes/basis are always [1,0,0], [0,1,0], and [0,0,1] -- x, y, and z.


Given: One axis in an arbitrary-basis 2D coordinate system

If you have one axis in an arbitrary-basis 2D coordinate system, the other axis is the orthogonal vector.

To rotate a vector orthogonally counter-clockwise:

[x_new, y_new] = [ -y_old, x_old]

To rotate a vector orthogonally clockwise:

[x_new, y_new] = [ y_old, -x_old]

To summarize:

Given: x-axis = [ a,  b]
Then:  y-axis = [-b,  a]

Given: y-axis = [ c,  d]
Then:  x-axis = [ d, -c]

Given: Two axes in an arbitrary-basis 3D coordinate system

To do this, find the cross product.

[a,b,c] x [d,e,f] = [ b*f - c*e, c*d - a*f, a*e - b*d ]

Following these three guidelines:

  • (x axis) x (y axis) = (z axis)
  • (y axis) x (z axis) = (x axis)
  • (z axis) x (x axis) = (y axis)

Given: One axis in an arbitrary-basis 3D coordinate system

There is not enough information to find the unique solution this problem. This is because, if you look at the second case (One axis in an arbitrary-basis 2D coordinate system), you first need to find an orthogonal vector. However, there are an infinite amount of possible orthogonal vectors to a single axis in 3D space!

You can, however, find one of the possible solutions.

One way to find an arbitrary one of these orthogonal vectors by finding any vector [d,e,f] where:

[a,b,c] = original axis
[d,e,f] = arbitrary orthogonal axis (cannot be [0,0,0])

a*d + b*e + c*f = 0

For example, if your original axis is [2,3,4], you'd solve:

2 * d + 3 * e + 4 * f = 0

That is, any value of [d,e,f] that satisfies this is a satisfactory orthogonal vector (as long as it's not [0,0,0]). One could pick, for example, [3,-2,0]:

2 * 3 + 3 *-2 + 4 * 0 = 0
  6   +  -6   +   0   = 0

As you can see, one "formula" that works to is [d,e,f] = [b,-a,0]...but there are many other ones that can work as well; there are, in fact, an infinite!

Once you find your two axes [a,b,c] and [d,e,f], you can reduce this back to the previous case (case 3), using [a,b,c] and [d,e,f] as your x and y axes (or whatever axes you need them to be, for your specific problem).


Normalization

Note that, as you continually do dot products and cross products, your vectors will begin to grow larger and larger. Depending on what you want, this might not be desired. For example, you might want your basis vectors (your coordinate axes) to all be the same size/length.

To turn any vector (except for [0,0,0]) into a unit vector (a vector with a length of 1, in the same direction as the original vector):

r  = [a,b,c]   
v  = Sqrt(a^2 + b^2 + c^2)   <-- this is the length of the original vector
r' = [ a/v , b/v , c/v ]

Where r' represents the unit vector of r -- a vector with length of 1 that points in the same direction as r does. An example:

r  = [1,2,3]
v  = Sqrt(1^2 + 2^2 + 3^2) = Sqrt(13) = 3.60555  <-- this is the length of the original vector
r' = [0.27735, 0.55470, 0.83205]

Now, if I wanted, for example, a vector in the same direction of r with a length of 5, I'd simply multiply out r' * 5, which is [a' * 5, b' * 5, c' * 5].

like image 73
Justin L. Avatar answered Nov 08 '22 03:11

Justin L.