Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

Calculate angle between two lines

Writer Mia Lopez
$\begingroup$

We have four points: a, b, c and d. We only know length of line cd and line ab. We also know that points c and d have same x coordinate, also points a and b have same x coordinate. Lines cd and ab are parallel. How can I find angle (marked as green) between lines ca and line db? Please provide example of calculations.

enter image description here

$\endgroup$ 10

4 Answers

$\begingroup$

Given the points with their coordinates $a_x, a_y ... d_x, d_y$, you can compute the angle of each line to the x-axis (using the arcustangens function), and then just compute the difference between these angles.

So you can compute the angles

$\alpha_0 = atan2(c_y-a_y, c_x-a_x)$

and

$\alpha_1 = atan2(d_y-b_y, d_x-b_x)$

(see the wikipedia link for the definition of the $atan2$ function).

The angle between the lines is then simply $\alpha_1-\alpha_0$


EDIT: The example:

  • $a_x = 100$, $a_y = 5$
  • $b_x = 100$, $b_y = 0$
  • $c_x = 0$, $c_y = 8$
  • $d_x = 0$, $d_y = 0$

Now compute

$\alpha_0 = atan2(c_y-a_y, c_x-a_x) = atan2(3, -100)$ $\alpha_1 = atan2(d_y-b_y, d_x-b_x) = atan2(0, -100)$

According to the cases described in this image from wikipedia:

enter image description here

We have

$\alpha_0 = atan(3/-100) + \pi \approx 3.1116016487329152$

$\alpha_1 = atan(0/-100) + \pi \approx 3.141592653589793$

And the angle is then the difference

$\alpha = \alpha_1 - \alpha_0 \approx 0.02999100485687789 \approx 1.718°$

$\endgroup$ 5 $\begingroup$

If you have two lines given by vector equations, say $\bf{p}+\lambda{\bf u}$ and ${\bf q}+\mu{\bf v}$, and the accute angle between the lines is $\theta$ then there is a well-known relationship:

$$\cos\theta = \left| \frac{{\bf u} \cdot {\bf v}}{\|{\bf u}\|\,\|{\bf v}\|} \right|$$

Notice that only the directions ${\bf u}$ and ${\bf v}$ of the two lines are needed.

If a line passes through points ${\bf a}$ and ${\bf c}$ then the line has direction ${\bf c}-{\bf a}$ because ${\bf c}-{\bf a}$ is the vector from ${\bf a}$ to ${\bf c}$. If you know all of the coordinates of the points then you can work out the direction vectors of the two lines and then apply the formula to get $\cos\theta$. Then use $\cos^{-1}$ to get $\theta$.

$\endgroup$ 2 $\begingroup$

we make a line parellel to the line $bd$, showed in this picture:enter image description here

then the angle you want is equal to the angle $\angle cad'$, and $dd'=ab$, because $ab\parallel cd$. so $cd'=cd-ab$.

now we can calculate the angle $\angle cad'$ in the triangle $\bigtriangleup cad'$. $$\cos(\angle cad')=\frac{ac^2+bd^2-d'c^2}{2\cdot ac\cdot bd}$$ then you have the angle by the function $\arccos()$.

In fact your inital conditions are not enough. from the two following pictures, we know that:enter image description hereenter image description here

1) when we only know the length of $ab$ and $cd$, the angle between $ac$ and $bd$ depends the distance between $ab$ and $cd$;

2) though $ab$ and $cd$ has a certain distance $\Delta x$, the angle between $ac$ and $bd$ depends also the hight of $ab$.

$\endgroup$ 9 $\begingroup$

If I understand you question correctly: cd and ab are parallel. So you can shrink your problem to a triangle. Where your requested angle (let's call him $\alpha$) depends on the angles of $cdb$ (here $\beta$) and $dca$ (here $\gamma$) or any other two angles in your figure.

Thus all these three angles must be $180° = \alpha + \beta + \gamma$ in the sum.

So I think your problem is under determined.

$\endgroup$ 2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy