Calculating an Angle from $2$ points in space
Assuming this is relative to the origin (as John pointed out): Given two position vectors $\vec p_1$ and $\vec p_2$, their dot product is:
$$\vec p_1\cdot \vec p_2 = |\vec p_1| \cdot |\vec p_2| \cdot \cos \theta$$
Solving for $\theta$, we get:
$$\theta = \arccos\left(\frac{\vec p_1 \cdot \vec p_2}{|\vec p_1| \cdot |\vec p_2|}\right)$$
In a 2D space this equals:
$$v = \arccos\left(\frac{x_1x_2 + y_1y_2}{\sqrt{(x_1^2+y_1^2) \cdot (x_2^2+y_2^2)}}\right)$$
And extended for 3D space:
$$v = \arccos\left(\frac{x_1x_2 + y_1y_2 + z_1z_2}{\sqrt{(x_1^2+y_1^2+z_1^2) \cdot (x_2^2+y_2^2+z_2^2)}}\right)$$
I will assume that you mean the angle of the line from p1 to p2 with respect to the x-axis
This is the best I can do given the information you have provided.
In any case, the official mathsy way would be to find the dot product between the two, and divide by the magnitude of p1-p2 and take the arccossine.
v = (normalized vector from p1 to p2)
theta = arccos( v * <1,0> ) (dot product)
You can normalize a vector by dividing every term by the magnitude (length) of the entire vector.
For 3D, the same thing applies:
theta = arccos( v * <1,0,0> ) (dot product)
You could also possibly mean the angle between the line from the origin to p1 and the line from the origin to p2.
You can do this with dot products, as well; but both vectors must be normalized.
theta = arccos( a * b ) (dot product)
where a
is the normalized vector from the origin to p1 and b
is the normalized vector from the origin to p2.