3

A line can be defined by two numbers : distance of line to origin and the angle from the origin to closest point on the line. Is there a formula to find the coordinates of intersection of two lines given this representation?

I can go to y=a*x+b representation for each line and calculate intersection point using basic algebra. However, vertical lines behave poorly. I can do a if (angle == 0 or angle == pi){.. check, but checking if two doubles are equal is pointless.

Stepan
  • 1,093
  • lol, you have asked this question several times and people answer the obvious way, kinda weird you accepted the answer in your last question, the answer below is basically the same. – Anonymous Oct 30 '16 at 21:41
  • @Anonymous You are not correct. The answer is different. It turns out I can use the ax+by=1 form to define any line without the "if line is vertical - deal with a special case". This solves a lot of my design problems. I am glad that you follow my progress, anonymous. – Stepan Oct 30 '16 at 21:48
  • yes but initally you were giving an angle as a parameter, If you try to transform it to ax+by=1, a or b will be a function of this angle and you will end up basically in the same scenario. – Anonymous Oct 30 '16 at 21:53

1 Answers1

3

You can write the lines as $ax+by=c$ and $dx+ey=f.$ (This includes vertical lines.) Now, to find the intersection point you solve de system

$$\begin{cases}ax+by&=c\\ dx+ey&=f\end{cases}$$ to get

$$x=\dfrac{ce-bf}{ae-bd},\quad y=\dfrac{af-cd}{ae-bd}.$$ (Of course, this only works if the lines are not parallel.)

mfl
  • 29,399