# How to calculate this angle from 2 points in 3d space?

How do I find the following angle $$a$$ given $$2$$ points $$(x, y, z)$$ in $$3$$-dimensional space?

I've drawn $$2$$ points, one in green, one in red. The curved black line being the earth, and the normal vector is perpendicular to the earth. Green point is on the ground, and red point will always be above ground. Can assume earth is centered at $$(0, 0, 0)$$ Edit: can assume red vector is pointing in opposite direction than drawn.

Let $$\vec{p}_r = (x_r, y_r, z_r)$$ be the red point, and $$\vec{p}_g = (x_g, y_g, z_g)$$ be the green point. The direction unit vectors are then $$\hat{r} = \frac{\vec{p}_r - \vec{p}_g}{\left\lVert \vec{p}_r - \vec{p}_g \right\rVert}, \quad \hat{g} = \frac{\vec{p}_g}{\left\lVert \vec{p}_g \right\rVert}$$ where $$\lVert\vec{p}\rVert = \sqrt{\vec{p} \cdot \vec{p}} = \sqrt{x^2 + y^2 + z^2}$$.
The angle $$\theta$$ between the two unit vectors fulfills \begin{aligned} \cos\theta &= \hat{r} \cdot \hat{g} \\ \sin\theta &= \left\lVert \hat{r} \times \hat{g} \right\rVert \\ \end{aligned} and usually you use $$\theta = \arccos(\hat{r} \cdot \hat{g})$$.
The angle between two vectors can be given by the dot product. More specifically, if $$a$$ and $$b$$ are vectors, then $$a\cdot b = \|a\|\|b\|\cos\theta,$$ where $$\|a\|$$ is the length of $$a$$, $$\|b\|$$ is the length of $$b$$, and $$\theta$$ is the angle between the two (in radians!). So here you have $$a= (1,1,1)$$, $$b =(1,1,1.3)$$, then you can compute their lengths and solve for $$\theta$$.
• rather than $(1,1,1.3)$, don't we need the vector formed between the points $(1,1,1.3)$ and $(1,1,1)$? Feb 25, 2021 at 0:40
• Sorry, I misread your diagram. Yes, in that case, you would have $a = (1,1,1)$ and $b = (1,1,1.3) - (1,1,1)$.