# Cross Product and Dot Product Computation : Vector Calculations

## Cross Product and Dot Product

Our previous article discussing nuances of vector calculus presented features of the dot product and cross product. These vector computations, though not too complex, are nevertheless fundamental to performing higher level methods. This article provides proofs for these functions to foment comprehension of their governing dynamics. Furthermore, we analyze several examples piece by piece in an effort to make the implementation of these techniques clear.

## Proofs

##### Dot Product Proof:

As the previous vector calculus article explicates, the dot product is a vector technique that returns a real value when multiplying vectors in the following fashion:

\overrightarrow{a} = < a_1,a_2,a_3 >\newline \overrightarrow{b} = < b_1,b_2,b_3 >\newline a\cdot b = a_1b_1+a_2b_2+a_3b_3

Also as previously discussed, the dot product is particularly useful for identifying the angle between two vectors by the function:

a\cdot b = |a||b|cos\theta

With the sheer importance of this function, which states that the dot product is equal to the product of the magnitudes of the vectors and the cosine of the angle between them, a proof of this function will be provided in conjunction with the image below:

Firstly, we invoke the Law of Cosines to establish a quantitative relationship between the vectors constituting this system:

|\overrightarrow{AB}|^2 = |\overrightarrow{OA}|^2+|\overrightarrow{OB}|^2-2|\overrightarrow{OA}||\overrightarrow{OB}|cos\theta

Next, we substitute ‘AB’ with ‘a-b’, ‘OA’ with ‘a’ and ‘OB’ with ‘b’:

|\overrightarrow{a}-\overrightarrow{b}|^2=|\overrightarrow{a}|^2+|\overrightarrow{b}|^2-2|\overrightarrow{a}||\overrightarrow{b}|cos\theta

We may see here that the left side of the equation hosts the statement |a-b|^2. We next rearrange this side of the equation with some basic arithmetic:

|\overrightarrow{a}-\overrightarrow{b}|^2 =(\overrightarrow{a}-\overrightarrow{b})\cdot(\overrightarrow{a}-\overrightarrow{b})\newline =\overrightarrow{a}\cdot\overrightarrow{a}-\overrightarrow{a}\cdot\overrightarrow{b}-\overrightarrow{b}\cdot\overrightarrow{a}+\overrightarrow{b}\cdot\overrightarrow{b}\newline =|\overrightarrow{a}|^2-2\overrightarrow{a}\overrightarrow{b}+|\overrightarrow{b}|^2

If we substitute this output into the expanded equation, we get:

|\overrightarrow{a}|^2-2\overrightarrow{a}\overrightarrow{b}+|\overrightarrow{b}|^2=|\overrightarrow{a}|^2+|\overrightarrow{b}|^2-2|\overrightarrow{a}||\overrightarrow{b}|cos\theta

Finally, we arithmetically manipulate this function to yield:

-2\overrightarrow{a}\cdot\overrightarrow{b}=-2|\overrightarrow{a}||\overrightarrow{b}|cos\theta\newline \overrightarrow{a}\cdot\overrightarrow{b}=|\overrightarrow{a}||\overrightarrow{b}|cos\theta

This proof efficaciously demonstrates the validity of the relationship between the dot product and the product of vector magnitudes with the cosine of the angle between them.

An additionally helpful interpretation comes from isolating the angle on one side of the angle so it may be readily computed:

cos\theta=\frac{\overrightarrow{a}\cdot\overrightarrow{b}}{|\overrightarrow{a}||\overrightarrow{b}|}

This helpful representation demonstrates how the angle between vectors can be computed by the quotient of the dot product of the vectors and the product of vector magnitudes. For another take on proving the dot product, consult this excellent walkthrough which can be found here.

##### Cross Product Proof:

We just witnessed the validation of the dot product, but what of the cross product? Again, as a refresher of previous statements made in the previous article, the cross product can also be used for the identification of the angle between two vectors. However, the cross product is particularly useful for identifying another vector orthogonal to both of the vectors in three dimensions. The unique aspect associated with this function is the fact that a vector product is returned rather than a real number. Recall that the standard function for computing the cross product is as follows:

\text{Suppose we have vectors ‘a’ and ‘b’ such that:} \newline \overrightarrow{a} = < a_1,a_2,a_3 >\newline \overrightarrow{b} = < b_1,b_2,b_3 >\newline \text{Then:}\newline \overrightarrow{a} \times\overrightarrow{b}=< a_2b_3-a_3b_2, a_3b_1-a_1b_3, a_1b_2-a_2b_1 >

We can demonstrate this as true with the use of matrices. Let us first examine a second order matrix and the computation of its determinants:

\begin{vmatrix} a & b \\ c & d\end{vmatrix}=ad-bc

Simple enough, right? Well, when working with three-dimensional vectors, we kick it up a notch by breaking it up into three separate groups, then take the determinant of each of those groups:

\begin{vmatrix} a_1 & a_2 & a_3 \\ b_1 & b_2 & b_3\\ c_1 & c_2 & c_3 \end{vmatrix}= a_1\begin{vmatrix} b_2 & b_3 \\ c_2 & c_3\end{vmatrix}-a_2\begin{vmatrix} b_1 & b_3 \\ c_1 & c_3\end{vmatrix}+a_3\begin{vmatrix} b_1 & b_2 \\ c_1 & c_2\end{vmatrix}\newline \begin{vmatrix} a_1 & a_2 & a_3 \\ b_1 & b_2 & b_3\\ c_1 & c_2 & c_3 \end{vmatrix}=a_1(b_2c_3-b_3c_2)-a_2(b_1c_3-b_3c_1)+a_3(b_1c_2-b_2c_3)

These deployments of matrices and computation of their respective determinants arrives at how cross products are too function. But, what of computing the angle between vectors? And for that matter, what of discerning the orthogonal vector to both of them? Well, to do so simply requires taking the magnitude of the cross product:

|\overrightarrow{a}\times\overrightarrow{b}|=|\overrightarrow{a}||\overrightarrow{b}|sin\theta

Briefly, we may reorganize this function such that computation of the angle is much more accessible:

sin\theta=\frac{|\overrightarrow{a}\times\overrightarrow{b}|}{|\overrightarrow{a}||\overrightarrow{b}|}

## Dot Product Computations

While it may be insightful to observe the laws which govern the operations we employ, a concept can only confidently when applied in action. So, this subsequent section will examine in thorough order the application of dot product computations.

##### Computation of Dot Product From Vector Components

Suppose we have vectors ‘a’ and ‘b’ and we desire to compute the dot product:

\overrightarrow{a} = < 5,4,.25 >\newline \overrightarrow{b} = < 6,-3,-8 >\newline

Let us first re-establish the function that permits computation, then substitute our variables:

a\cdot b = a_1b_1+a_2b_2+a_3b_3\newline \overrightarrow{a}\cdot\overrightarrow{b}=(5)(6)+(4)(-3)+(.25)(-8)\newline \overrightarrow{a}\cdot\overrightarrow{b}=(30)-(12)-(2)\newline \overrightarrow{a}\cdot\overrightarrow{b}=16
##### Computation of Angle Between Two Vectors With Dot Product

Suppose we have two vectors ‘a’ and ‘b’ such that:

\overrightarrow{a} = < 3,-1,-5 >\newline \overrightarrow{b} = < -2, 4,3 >\newline

Now, how might we compute the angle between these vectors? First, let us call to action the function which associates the vector dot product with the angle:

cos\theta=\frac{\overrightarrow{a}\cdot\overrightarrow{b}}{|\overrightarrow{a}||\overrightarrow{b}|}

We can rearrange this equation with the dot product function such that:

cos\theta=\frac{a_1b_1+a_2b_2+a_3b_3}{|\overrightarrow{a}||\overrightarrow{b}|}

Furthermore:

|\overrightarrow{a}|=\sqrt{a_1^2+a_2^2+a_3^2}\newline\text{and}\newline |\overrightarrow{b}|=\sqrt{b_1^2+b_2^2+b_3^2}

Thus, our comprehensive function appears as:

cos\theta=\frac{a_1b_1+a_2b_2+a_3b_3}{(\sqrt{a_1^2+a_2^2+a_3^2})(\sqrt{b_1^2+b_2^2+b_3^2})}\newline \newline cos\theta=\frac{(3)(-2)+(-1)(4)+(5)(3)}{(\sqrt{(3^2)+(-1^2)+(5^2)})(\sqrt{(-2^2)+(4^2)+(3^2)}}\newline cos\theta=\frac{5}{(\sqrt{29})(\sqrt{29})}\newline cos\theta=\frac{5}{29}\newline \theta=cos^{-1}(\frac{5}{29})\newline \theta=80.07˚
##### Discerning If Two Vectors Are Orthogonal

Suppose we have two vectors ‘a’ and ‘b’ and we wish to determine if these are orthogonal:

\overrightarrow{a} = < 3,-1,-5 >\newline \overrightarrow{b} = < -2, 4,3 >\newline cos\theta=\frac{a_1b_1+a_2b_2+a_3b_3}{(\sqrt{a_1^2+a_2^2+a_3^2})(\sqrt{b_1^2+b_2^2+b_3^2})}\newline \newline cos\theta=\frac{(-5)(6)+(3)(-8)+(7)(2)}{(\sqrt{(-5^2)+(3^2)+(7^2)})(\sqrt{(6^2)+(-8^2)+(2^2)}}\newline cos\theta=\frac{-40}{(\sqrt{83})(\sqrt{104})}\newline cos\theta=\frac{-40}{92.9}\newline \theta=cos^{-1}(-.43057)\newline \theta=115.5˚

Because the angle between vectors ‘a’ and ‘b’ is not equal to 90˚ degrees, we may infer that these vectors are not orthogonal.

## Cross Product Computation

As with our discussion of the dot product, it could be quite useful to work through some examples of computing the cross product to get a better understanding of the operations they support.

##### Computation of Cross Product From Component Vectors

Suppose we have two vectors ‘a’ and ‘b’ of the form:

\overrightarrow{a} = < 3,-1,-5 >\newline \overrightarrow{b} = < -2, 4,3 >\newline

Consider how we might compute the cross product of these vectors. First, let us call to action the function that makes this possible, and subsequently, substitute values:

\overrightarrow{a} \times\overrightarrow{b}=< a_2b_3-a_3b_2, a_3b_1-a_1b_3, a_1b_2-a_2b_1 > \newline \overrightarrow{a} \times\overrightarrow{b}= < (-1)(3)-(-5)(4), (-5)(-2)-(3)(3), (3)(4)-(-1)(-2) >\newline \overrightarrow{a} \times\overrightarrow{b}= < 17, 1, 10>
##### Discerning the Angle Between Two Vectors

As with the dot product, the cross product can be implemented to discern the angle between two vectors. Let us do so with vectors ‘a’ and ‘b’:

\overrightarrow{a} = < 1,2,3 >\newline \overrightarrow{b} = < -1, 1,2 >\newline

Let’s first call to action the function which permits the computation of the angle:

sin\theta=\frac{|\overrightarrow{a}\times\overrightarrow{b}|}{|\overrightarrow{a}||\overrightarrow{b}|}\newline sin\theta=\frac{|< a_2b_3-a_3b_2, a_3b_1-a_1b_3, a_1b_2-a_2b_1 >|}{{(\sqrt{(a_1^2)+(a_2^2)+(a_3^2)})(\sqrt{(b_1^2)+(b_2^2)+(b_3^2)}}}\newline sin\theta=\frac{|< (2)(2)-(3)(1), (3)(-1)-(1)(2), (1)(1)-(2)(-1) >|}{{(\sqrt{(1^2)+(2^2)+(2^2)})(\sqrt{(-1^2)+(1^2)+(2^2)}}}\newline sin\theta=\frac{|< 1, -5, 3 >|}{{(\sqrt{(14)})(\sqrt{(6)})}}\newline sin\theta=\frac{5.916}{9.165}\newline sin\theta=.645508\newline \theta=sin^{-1}(.645508)\newline \theta=40.20˚

## Future Endeavors

This article elucidated both the proofs associated with the cross and dot product of three dimensional vectors, and also explicated some comprehensive examples. If you’d like broader insight into vector calculus, check out this article which explains the various aspects of the subject in detail. Otherwise, future articles will discuss alternative subjects in this style including parametric equations with vector functions, vector differentiation and integration, and applying these methods for computing arc length and curvature. Hopefully this has proven to be a useful resource for you, and if it has, the other guides will prove to be useful utilities.

As a page focused on utilizing mathematics for programming, expect to see some articles later discussing the creation of a program that can code these functions to make this automated, and also how to use vector calculus in data driven programs. Before doing so, however, check out the guide for designing a web scraper that can acquire all the data you need to practice manipulation of data with vector functions.