# How to deteremine the angle between Sun and 2 probes?

I have the orbital position and velocity and the orbital parameter of 2 spacecraft at LEO, how to define the angle between Sun - Probe 2 - Probe 1 in ECI frame (If you imagine at a point sun then behind it probe 2 and behind of that probe 2 is Probe 1, so at some point 3 objects could be one line so angle zero but most of the time it will be different as both probes are rotating around earth). like this picture,

From this source and from this souce (4.3 algo) I got the unit vector of sun position in ECI Frame. But how can I calculate the angle? Long story in short, Probe 1 is communicating with Probe 2 with laser beam but behind the Probe 2 if sun will appear, communication could be an issue, so I need to understand the angle variations.

Since you have all three positions in the same frame (in this case ECI but it doesn't matter which one for the purposes of your question), you calculate the angle the same way I did in this answer.

The cosine of the angle between any two unit vectors $$\mathbf{\hat{a}}$$ and $$\mathbf{\hat{b}}$$ is their dot product:

$$\cos(\theta)=\mathbf{\hat{a}} \cdot \mathbf{\hat{b}}$$

so if the positions of the two spacecraft and the Sun are $$\mathbf{x_1}$$, $$\mathbf{x_2}$$ and $$\mathbf{x_{Sun}}$$, then the unit vectors drawn from the observer spacecraft 1 to the Sun and spacecraft 2 are:

$$\mathbf{\hat{r}_{Sun}} = \frac{\mathbf{x_{Sun}} - \mathbf{x_1}}{|\mathbf{x_{Sun}} - \mathbf{x_1}|}$$

$$\mathbf{\hat{r}_2} = \frac{\mathbf{x_2} - \mathbf{x_1}}{|\mathbf{x_2} - \mathbf{x_1}|}$$

and the angle between them is

$$\theta=\arccos(\mathbf{\hat{r}_{Sun}} \cdot \mathbf{\hat{r}_2})$$

where 0 $$\le \theta < \pi$$ in radians, or 0 $$\le \theta <$$ 180° in degrees.

In the middle of a computer program if you want to make sure that spacecraft 2 is farther from the Sun than some critical angle $$\theta_{crit}$$ that you choose, then just check that

$$\mathbf{\hat{r}_{Sun}} \cdot \mathbf{\hat{r}_2} > \cos(\theta_{crit}).$$