c++ program to find dot and cross product

This post shows you how to code a basic program in cpp that can calculate the dot and cross product of two vectors. 

Cpp program to find the Dot and Cross product of two vectors

Assume that there are two vectors A = a1i + a2 j + a3k and B = b1i + b2j
+ b3k and the dot product of them can be found as 

A.B = a1.b1 + a2.b2 + a3.b3 .

And the Cross product of A and B can be found as 

AXB = i(a2.b3 - a3.b2) + j(a3.b1 -
a1.b3) + k(a1.b2 - a2.b1).

To mimic the vector we can use c++'s struct or class or array.

But I
suggest you to use the struct or class to mimic the vector because you may
implement more functions as addition, subtraction, etc.

In this snippet code I have used the cpp's struct.

The Cross product of two vectors "a" and "b" is a new vector that is perpendicular to both "a" and "b" and the magnitude is equal to
the bounded area thru both vectors.

The Dot Product is a scalar quantity
which is also equal to the dot of projection vector of "a" on to "b" with
the magnitude of "b".

Share this Post

Leave a Reply

Your email address will not be published. Required fields are marked *