I have the $x$ and $z$ coordinates of 3 points ($S,ドル $E$ and $W$) lying on the $x,ドル $z$ plane. I want to calculate the outer angle made by point $E,ドル and the line going through points $S$ and $E,ドル as shown in figure 1.
$\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:$ figure 1
$\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:$figure 1
I know I can use the cosine rule to calculate this - by calculating the lengths of $SE,ドル $EW$ and $SW$ and then plugging these values into the law of cosines equation. But this involves a lot of calculations. Is there a quicker way?
To calculate the angle between $SE$ and the vertical I used the equation:
$$\theta = \cos^{-1} \frac{1 - E_y}{\sqrt{(E_y - 1)^2 + (E_z - 1)^2}}.$$
Which was derived from the dot product equation. Is there a similar equation to calculate the outer angle between $SE$ and $EW$? (the yellow elbow flextion angle shown in figure 1)
-
$\begingroup$ Find the angle between $EW$ and vertical line, subtract one from another. $\endgroup$Kaster– Kaster2015年02月26日 21:48:52 +00:00Commented Feb 26, 2015 at 21:48
-
1$\begingroup$ You mention x and z coordinates, but the picture in in the y z coordinates. $\endgroup$John Alexiou– John Alexiou2015年02月26日 22:04:57 +00:00Commented Feb 26, 2015 at 22:04
1 Answer 1
See https://stackoverflow.com/a/21486462/380384
Or follow these steps
- Create two vectors $A=(S-E)$ and $B=(W-E)$
- Calculate the dot product $$\cos\theta = A\cdot B = A_x B_x + A_z B_z$$
- Calculate the magnitude of the cross product $$\sin\theta = |A \times B| = A_x B_y - A_y B_x $$
- Use the ATAN2() function to get the included angle $$\theta = {\rm atan2}(\sin \theta, \cos \theta)$$
- Get the desired angle by $\pi - \theta$