“True angle” between unit vector on sphere

I have a sphere with center O = (0,0,0) and radius r=1. I want to calculate "true" angles phi(i) between points Pi lying on this sphere.

From cartesian coordinate, I have :

$cos(phi) = x1 x2 + y1 y2 + z1 z2$

The problem is that this angle change according to positions of points on the sphere. For example, if severals points make a loop on the equator, my sum of phi(i) would be 360 degrees. If it's at the top of the sphere, the sum of phi(i) would be <360 degrees.

Does anyone knows how to correct that, a paper explaining this problem ? If points describe a rotation, what about changement of axis of rotation and angle calculation ?

We told me to estimate the plane containing the points and to project them on it. I used :

https://stackoverflow.com/questions/1400213/3d-least-squares-plane

and

https://stackoverflow.com/questions/8942950/how-do-i-find-the-orthogonal-projection-of-a-point-onto-a-plane

I think you really want $\cos \phi = (\mathbf{x}_{n+1} - \mathbf{x}_n) \cdot (\mathbf{x}_{n+2} - \mathbf{x}_{n+1})$, i.e. $\cos \phi = (x_3 - x_2)(x_2 - x_1) + (y_3 - y_2)(y_2 - y_1) + (z_3 - z_2)(z_2 - z_1)$.
Your equation measures the angle formed by 2 consecutive points and the origin, $\angle x_1 O x_2$. My equation measures the supplement of $\angle x_1 x_2 x_3$.