During studies I regarded vector calculations as a terrible discipline. I remember quite well: At the end of the first week of school a teacher “performed” the calculation of the balance point of a triangle by the use of vectors. At the end of this performance one of the students packed his staff, said that was it for me, quit the school and never came back. It was really awful...I tell you
Now everything is different. I learned to like vectors and use then quite often. If something has to be calculated in the 3 dimensional spaces, it has to be done by the usage of vectors. No big deal.
By the way: 2 dimensional vectors should not be mixed up with complex numbers as these are really different things. I think that’s an important point.
To identify a vector is done in different ways. Some put an arrow on top of the sign some don’t. Some write the sign of a vector in strange gothic characters and some just write a capital letter for a vector similar to the sign for a matrix. So do I.
The length of a vector in 3 dimansional spaces is according to Pythagoras:
or in multi-dimensional spaces:
the root of the sum of the square of all expansions. This length is quite often named the norm of the vector and it’s sign is
There are different kinds of norms defined:
So take care with all this different kinds of norms
The unit vector is a vector that just defines a direction. It’s length is 1. It is usually marked by a “^” over the character. The unit vector is quite useful in vector calculations. The unit vector to a given vector V is
For illustration I use 3 dimensional vectors here. The definitions are the same fur multi-dimensional vectors (except for the cross product).
Subtraction of a vector from another vector
The resulting vector is the dark grey vector U - V. The light grey vector shows the distance vector between U and V. That means the distance between U and V can be calculated by subtracting V from U and then calculating the length of the resulting vector.
An application of vector additions is the superposition of speeds. If for instance an air plane flies from New York to Zurich and there is a strong jet stream blowing, the speed of the wind and the flying speed of the air plane in the air is add together and that gives the speed over ground.
That’s just a stretching or shortening of the vector while it's direction remains the same.
Or in multidimensional spaces:
There are several different ways to write the dot product. It can be a dot like U∙V or brackets like
In some articles they use the dot product to calculate the length of a vector. Therefor the dot product of the vector with itself is built and the root is taken from that:
Others express the dot product as
This is a matrix multiplication of the transposed of U by V. To transpose a vector of n dimensions lays it flat on a line and converts it to a matrix of one row and n columns. The multiplication of this by V is the same as computing the dot product of them.
That means if you have a vector product U x V and the both vectors are laying on a plane in front of you (virtually) turn the first vector towards the second and if this rotation is clockwise, the resulting vector looks away from you (the screw in the picture is turned clockwise and it moves upward. That’s the direction the resulting vector looks).
Mathematically U x V is:
An application of the vector product is the calculation of the Lorenz force. If an electrically charged particle moves through a magnetic field it is exposed to the Lorenz force which is:
With F as the force vector, q the load of the particle, V the speed vector and B the magnetic field vector.
Another possibly more tangible application is the Coriolis force. See
https://en.wikipedia.org/wiki/Coriolis_force
There is
and
now
and with this:
and with the equation for cos(α) and sin(α) from above:
That can be simplified to
The same approach for p2y gives:
These two equations describe operations that can be expressed as one matrix multiplication
and the matrix
is a 2*2 rotation matrix.
If the vectors P1 and P2 would be 3 dimensional, the rotation matrix would be 3*3 too. Only, it would describe a rotation in one plane only. A vector with the dimensions x, y and z would be rotated by the angle α in the x-y plane by the rotation matrix:
and the rotation matrix to rotate in the y-z plane would be:
and for the x-z plane:
That’s the way to build a rotation matrix. For multi-dimensional spaces it’s basically the same. Only the matrix gets more columns and rows.
Maybe an interesting application is to draw an ellipse from a DXF definition. The DXF file format is a vector based format to define technical drawings in CAD and CAM. In this format an ellipse is defined by its position (x0, y0), the half axis A and B, a start angle (α1), an end angle (α2) and the inclination of its main axis (φ).
Ellipse segment embedded into a form (blue contour).
To draw this ellipse the equation for the centre point and the half axes:
can be used.
Starting from α1 and running to α2 that draws the sector of an ellipse without an inclination. To include the inclination we just have to rotate the vector
by the angle φ. That’s
and calculate the points from α1 to α2 like
I implemented this in a small DXF file reader. Or better to say I extended the DXF sample of
https://www.codeproject.com/Articles/156522/DXF-Import-NET-Read-and-View-AutoCAD-Format-Files
to handle polylines, circles, ellipses and splines. O.k. I think it does not make too much sense to describe the DXF file format here. The interested reader might see at
https://www.autodesk.com/techpubs/autocad/acad2000/dxf/entities_section.htm
But the sample project, including some sample DXF files I found, is in the download link at the bottom of this article.
Some advanced vector calculations
For a AI-algorithm I recently faced the problem to set a perpendicular from a point V onto a line or a plane. I think that’s a good example to see that vectors can be quite cool
Perpendicular from a point V onto a line
To set a perpendicular from a point V onto a line defined by 2 points P1 and P2 like:
In the 3 dimensional space, the normal equation for a line
can be used.
With the normal vector N which is perpendicular to the line.
Now a vector U - V which is perpendicular should be found. Whereas U should lay on the line. That means
and
With k as a multiplication factor.
As U - V is perpendicular to the line:
This is basically a scalar product like:
With the equation from above:
That can be resolved for k:
This used in
Gives the point U where the perpendicular comming from V meets the line. And the solution for k can easy be extended to more dimensional spaces. That’s really cool
(Please note that U and V are principally points, but I interpret them as vectors here.)
Perpendicular from a point V onto a plane
Is quite similar.
The point where the perpendicular meets the plane is U. This U shall be determined.
I use the unit vector of N which is perpendicular to the plane:
where
(from the above equation for the plane)
Whit this unit vector we can say
With k as a scalar factor.
U inserted into the equation for the plane gives
or the equation for U:
and this resolved for k:
This k used in
Gives the point U where the perpendicular starting at V meets the plane. Similar to the situation with the line the formula for k can easy be extended to more dimensional spaces as well