views:

127

answers:

5

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.

A: 

Are you talking about a typical 3coordinate system like the one used in a 3D engine?

With just a vector you can't find the other two, the only information you will have it the plane on which they lay.. but they can be at any angle also if they're perpendicular with the only one vector you have.

Jack
A: 

The question title says it's the vector of an axis, but the description says the vector is not aligned to an axis. Please clarify.

Aramis wyler
Think about two frame of reference, not aligned with each other...
dmckee
They have a (presumably non-zero) vector. They want to find two more non-zero vectors that are orthogonal to each other and orthogonal to the original vector.
This is not an answer. Why couldn't this have been a comment?
Justin L.
User207442 you are correct. Aramis: in the desctiption i mean the vector id not aligned to the world x, y or z axis
Stoff81
+3  A: 

Having only one axis isn't enough, since there are still an infinite number of axes that can be in the perpendicular plane.

If you manage to get another axis though, you can use the cross product to find the third.

Ignacio Vazquez-Abrams
How can it be true that "Having only one axis isn't enough" when you immediately say there are an infinite number of suitable vectors and in your next paragraph you say how to proceed given that a suitable vector has been found?
Don't make me link to the entry on "if" at dictionary.reference.com...
Ignacio Vazquez-Abrams
+8  A: 

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].

Justin L.
If he's using simulation or game software, he may have the objects rotation, which would make finding the other two axes easy enough.
LanceH
The question is honestly pretty vague =/
Justin L.
So in summary then Justin: First you use the dot product rule that two orthogonal vector have a dot product of zero, to get the second axis.Then use the cross product of these two axis to get the 3rd axis.I understand all this. The only question i have is how do you get the arbitrary orthogonal axis of say a vector of {4.418020, -6.474061, -6.210284}
Stoff81
How have you arrived at choosing [3,-2,0] as you orthogonal axis?
Stoff81
OK so i see how you have got [b, -a, 0] but this would not always work for any vector would it? it is specific to [2, 3, 4]
Stoff81
`[b,-a,0]` will work for any vector, by the nature of the dot product. *An* (but not the only) orthogonal vector of `[4.418020, -6.474061, -6.210284]` is `[-6.474061, -4.418020, 0]`, by the virtue that the dot product (-28.6 + 28.6 + 0) = 0. That's one of the *infinite amount* of possible orthogonal vectors you could choose (Another simple one is `[6.474061,4.418020,0]`, in the form `[-b,a,0]`).
Justin L.
In the previous example, your third axis would be `[-27.437159,40.205757,-61.432365]`, if your original given axis was the x axis, or `[27.437159,-40.205757,61.432365]`, if your original given axis was the y axis.Note that, as you do dot products and cross products, the size of your next vector grows larger and larger, which might not be something that is desired. I have added a section to my post dealing with this.
Justin L.
A: 

If you have one vector (x,y,z) you can get one perpendicular vector to it as (y,-x,0) (dot-product is x*y-y*x+0*z = 0)

Then you take the cross-product of both to get the remaining perpendicular vector: (x,y,z) × (y,-x,0) = (0y+zx, yz-0x, -x²-y²) = (zx, yz, -x²-y²)

Ozan
Let (x,y,z)=(0,0,1). The vector (y,-x,0) is (0,0,0). That's a zero vector.
@user207442: The problem description said the vector is not aligned to an axis. If (x,y,z)=(0,0,1) finding the other two vectors is trivial.
Ozan