How to calculate the cosine between two line segments I'm preparing for my college maths exam in 2 weeks time and one question I came across that I'm not fully sure how to answer.
The question is 
Calculate the length of the line segments BD, BG, and the cosine
of the angle between these two line segments at the point B.
where B = (3, 3, 3), D = (6, 6, 1), G = (8, 8, 5)
I know I have to use the cosine formula but I am unsure what u and v would be in this case.
Any help is appreciated, thanks.
 A: Hint:
The vectors $$\vec {BD}=3\hat{i}+3\hat{j}-2\hat{k}$$
$$\vec {BG}=5\hat{i}+5\hat{j}+2\hat{k}$$
Length of $\vec{BD}=|\vec{BD}|$
Taking the dot product,
$$\vec{BD}\cdot\vec{BG}=|\vec{BD}||\vec{BG}|\cos\theta$$
which gives the value of $\cos\theta$
A: You can place $B$ at the Origin. Then corresponding for $D$ and $G$ we would get $D=(3,3,-2)$ and $G=(5,5,2)$. Then you van calculate the magnitudes of the two vectors $OB$ and $OG$ with the distance formula. The cosine can be calculated with the formula $cos\theta=\frac{|dot(OB)(OG)}{|OB||OG|}$
A: Use the distance formula to calculate the lengths (by the way, the distance formula is just Pythagorean theorem in case you didn't already know) to get the lengths of BD and BG. The distance formula between points $(x_1,y_1,z_1)$ and $(x_2,y_2,z_2)$ is reproduced below.
$$Length = \sqrt{(x_1-x_2)^2+(y_1-y_2)^2+(z_1-z_2)^2}$$
Plugging into this formula you get:
$$\overline{BD} = \sqrt{22} $$
$$\overline{BG} = \sqrt{54} =3\sqrt{6}$$
Regarding the cosine, you have two options.  You could use the definition of the dot product or you could use the Law of Cosines.  I'll include both methods and let you choose.  I'd recommend the dot product if you've heard of it and the Law of Cosines if not.
Dot product:
The dot product between two vectors is related to the cosine of the angle between the vectors by the formula below
$$\vec{BD}\cdot\vec{BG}=|BD||BG|cos(\theta)$$
or in words, 

the dot product of two vectors equals the product of their lengths times the cosine of the angle between them.

You obtain the vectors by taking the differences between the x and y coordinates (similar to how you did it in the distance formula
$$\vec{BD}=<(x_B-x_D),(y_B-y_D),(z_B-z_B)>$$
$$\vec{BD}=<-3,-3,2>;\vec{BG}=<-5,-5,-2>$$
$$\vec{BD}\cdot\vec{BG}=26$$
Plug into the dot product formula and solve for $cos(\theta)$
$$26 = \sqrt{22}\cdot3\sqrt{6}\cdot cos(\theta)$$
$$\frac{26}{6\sqrt{33}} = \cdot cos(\theta)$$
$$\frac{13\sqrt{33}}{99} = cos(\theta)$$
Law of Cosines
$$c^2=a^2+b^2-2ac\cdot cos(C)$$
You have a and b.  Use the distance formula to find c and solve for $cos(c)$
$$\overline{DG} = \sqrt{24} =2\sqrt{6}$$
$$cos(C) = \frac{24 - 22 - 54}{-2\cdot \sqrt{22\cdot 54}}$$
$$cos(C) = \frac{-26}{-6\sqrt{33}}$$
$$cos(C) = \frac{13\sqrt{33}}{99}$$
