Consider having two lines given by their start points ($A$ and $B$) and their angle with respect to the $x$-axis.

enter image description here

These are half-open lines, and the intersection may occur only after the starting points. For example, they do not intersect in the given image if $a>b$ or $a$ is negative.

  1. How can we tell if they cross from their angles?
  2. What is the fastest way to find the intersection?

I have two options: First, using an imaginary far endpoint, calculate the intersection of line segments. Second, treat them as two vectors.

But I think both are overkill, as a simpler solution might be available using the angles (instead of the endpoints).

  • 1
    $\begingroup$ 1. If they are parallel, what do you know about the angles? 2. If you know the angle, you know the slope ($m=\tan\theta$). You also know a point so you could find the two equations and... $\endgroup$ Jan 29 at 22:54
  • $\begingroup$ @BernardMassé For point 1, the exclusion is not when they're parallel. The lines do not continue beyond the start point. The intersection should be from the start point. It's a half-segment line if it is the right terminology. $\endgroup$
    – Googlebot
    Jan 29 at 22:58

Let Equation of line from A is:

$y=a_1 x+b_1$

And that of B is:

$y=a_2 x +b_2$

Where $a_1=tan (a)$ and $a_2=tan (b)$ . These lines intersect if the angle between them is less than $180^o$, that means $a\neq b$ or they are not parallel. This angle can be found from following formula:

$$tan(\theta)=\frac {a_2-a_1}{1+a_1a_2}$$

For second question you have to solve following system of equation which gives the ordinates of point of intersection:

$\begin{cases}y=a_1x+b_1 \\y=a_2x+b_2\end{cases}$

  • $\begingroup$ As I understand, your solution works for the whole line, not half-open line segment. For example, take $a=10$ and $b=20$ in the above picture. They do not intersect, but your method suggests an intersection (bellow point B, which is not on the given line, and not allowed). We want an intersection with the line starting from point B, not the line passing through point B. $\endgroup$
    – Googlebot
    Feb 1 at 0:08

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.