I can think of several different scenarios that you might ask about.
Given: Pre-existing coordinate system
In a 2D system, your axes / bases are always [1,0] and [0,1] - x and y axes.
In a three-dimensional system, your axes / bases are always [1,0,0] , [0,1,0] and [0,0,1] - x, y and z.
Given: One axis in a coordinate system with an arbitrary base
If you have one axis in a 2D coordinate system of an arbitrary basis, the other axis is an orthogonal vector.
To rotate a vector orthogonally counterclockwise :
[x_new, y_new] = [ -y_old, x_old]
To rotate a vector orthogonally clockwise :
[x_new, y_new] = [ y_old, -x_old]
Summarizing:
Given: x-axis = [ a, b] Then: y-axis = [-b, a] Given: y-axis = [ c, d] Then: x-axis = [ d, -c]
Given: Two axes in a three-dimensional coordinate system of an arbitrary basis
To do this, find a cross product.
[a,b,c] x [d,e,f] = [ b*f - c*e, c*d - a*f, a*e - b*d ]
Following these three recommendations:
- (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 a three-dimensional coordinate system of an arbitrary basis
There is not enough information to find a unique solution to this problem. This is due to the fact that if you look at the second case (one axis in a two-dimensional coordinate system of an arbitrary basis), you first need to find the orthogonal vector. However, there are an infinite number of possible orthogonal vectors for one axis in three-dimensional space!
However, you can find one of the possible solutions.
One way to find an arbitrary one of these orthogonal vectors is 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 decide:
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 is not [0,0,0] ). You can select, for example, [3,-2,0] :
2 * 3 + 3 *-2 + 4 * 0 = 0 6 + -6 + 0 = 0
As you can see, one “formula” that works is [d,e,f] = [b,-a,0] ... but there are many others that can work; in fact there is infinite!
Once you find the two axes [a,b,c] and [d,e,f] , you can reduce it to the previous case (case 3) using [a,b,c] and [d,e,f] as the x and y axes (or any axes you need to be for your specific problem).
Normalization
Note that as you constantly make point products and cross products, your vectors will start to grow more and more. Depending on what you want, this may not be desirable. For example, you might want your base vectors (your coordinate axes) to be the same size / length.
To turn any vector (except [0,0,0] ) into a unit vector (a vector of length 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' is a unit vector r is a vector with a length of 1 that points in the same direction as r . 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 r with a length of 5, I would simply propagate r' * 5 , which is [a' * 5, b' * 5, c' * 5] .