Example Code

Calculating the Angle between Two Vectors

Code and Documents

Attachment

This example calculates the angle between two vectors, using two different methods. The first method uses the following equation:
cos(theta) = ((Vector 1) . (Vector 2)) / (||Vector 1|| X ||Vector 2||) where the . (dot) is the dot product between the vectors and ||Vector|| = the magnitude of the vector.

The second method uses the complex LabVIEW math routines to calculate each vector phase. To compute theta, the VI calculates the difference between the phase of each vector.

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors