Euclidean vectors are very important quantity in mathematics, applied mathematics, physics, engineering etc. Formally vectors are those quantity which have both magnitude and direction. For example velocity. Velocity has both magnitude (Speed, like 2 Km/Hr) and direction (e.g. east). In programmer’s perspective, there are many situation where you need to compute different vector operations. For example consider a moving ball. To simulate the motion of ball, you must calculate the velocity of the ball. The ball has both magnitude (i.e rate of translation of position of center of the ball) and direction (e.g. axis x or y or z). This is just one example but there are various examples where vector operations are essential.

Now in this article, I will show you how to compute different vector operations like, sum of two vectors, multiplication by scalar, dot product, cross product, normalization etc in C++. I choose C++ instead of C because it is object oriented. The vector can be represented by an object. The components of vector along x, y and z axis will be the data member of the object. The data members are attributes of the object. Similarly different operations will be the member functions of the object. Now the vector object can completely represent the vector quantity.

Now in this article, I will show you how to compute different vector operations like, sum of two vectors, multiplication by scalar, dot product, cross product, normalization etc in C++. I choose C++ instead of C because it is object oriented. The vector can be represented by an object. The components of vector along x, y and z axis will be the data member of the object. The data members are attributes of the object. Similarly different operations will be the member functions of the object. Now the vector object can completely represent the vector quantity.