Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop p

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".

No comments:

Post a Comment