A list of vectors may be defined as:
V = V1x, V1y, V1z
V2x, V2y, V2z
...
Vnx, Vny, Vnz
This can be set up in IDL as
In IDL: C = A + B
If vectors are considered as arrows then adding vectors A
and B is done by moving arrow B, without changing its size or
direction, to place its tail at the head of arrow A. A new vector from
the tail of arrow A to the head of arrow B is the sum, C.
Mathematically vectors are added by adding their corresponding
components.
The following figure illustrates vector addition.
Vector addition works for two lists of vectors if the have the
same size and shape.
In IDL: B = s*A
A list of vectors, V, may also be multiplied by a scalar, s: T = s*V
In IDL: C = A - B
Vector subtraction works for two lists of vectors if the have the same size and shape.
In IDL: A dot B is simply TOTAL(A*B).
The dot product of a list of vectors, V, with a single vector, B
is in IDL: V##B
which gives a column of values, one for each dot product.
In IDL: this may be computed as SQRT(TOTAL(A*A)).
The lengths of a list of vectors, V, is found in IDL as:
total(V*V,1)
which gives a length for each vector in the list.
In IDL: AU = A/SQRT(TOTAL(A*A)).
The function UNIT does this operation: AU = UNIT(A).
In IDL: the angle between vectors A and B is given by ANG_A_B = ACOS(TOTAL(UNIT(A)*UNIT(B))) in radians (multiply by !RADEG to convert to degrees).
In IDL: For vectors A and B if TOTAL(A*B) is 0 then A and B are perpendicular.
In IDL: if A is an arbitrary vector and U is a unit vector, then the component of A parallel to U is given by TOTAL(A*U)*U.
For a list of vectors, V, a list of the components of V parallel
to a unit vector U is in IDL: U#(V##U)
which gives a list of vectors, one for each vector in V.
Transforming coordinates to a new system
This is very useful for transforming a set of vectors (or points)
from one coordinate system to another. Set up unit vectors along the
directions of the new x, y, and z axes. Find the components of the
original vectors along these unit vectors to get the x, y, and z
coordinates in the new coordinate system. If the original axis unit
vectors are also transformed this way they can be used to transform
the points back to the original coordinate system.
A method for 3-d vectors is the following. For vector A = (Ax,Ay,Az) find the smallest component (absolute value) and set the corresponding element of perpendicular vector B to 0. The remaining two elements of B are the remaining two elements of A switched and with one of them negated. For example, if Ay has the smallest absolute value, then B = (-Az, 0, Ax) is a vector perpendicular to A as may be seen by showing that the dot product is 0. The 2-d case given above is seen to be a special case of this method.
For 2-d vectors contained in the XY plane the cross product is a vector parallel to the z axis, and (Ax By - Ay Bx) is the signed area of the parallelogram with sides along A and B.
In general (3-d vectors included) |A x B| is the area (non-signed) of the parallelogram. If vectors A and B are parallel or antiparallel, then the area is 0 and the magnitude of the cross product is also 0.
In IDL: a function to compute C = A x B is called CROSS. If A and B are 3-D vectors, then the call is C = CROSS(A,B).
Let V_par and V_perp be orthogonal components
of V, then
V = V_par + V_perp.
If V_par is the component of V that is parallel
to the unit vector U_hat then
V_par = (V dot U_hat) U_hat.
It follows that V_perp = V - V_par.
In IDL: if V is a vector and U a unit vector, then
V_PAR = total(V*U)*U
V_PERP = V - V_PAR