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

1k Views Asked by At

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)$

Diagram

Edit: can assume red vector is pointing in opposite direction than drawn.

2

There are 2 best solutions below

0
On BEST ANSWER

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})$.

2
On

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