3
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ 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. $\endgroup$
    – Anonymous
    Commented Oct 30, 2016 at 21:41
  • $\begingroup$ @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. $\endgroup$
    – Stepan
    Commented Oct 30, 2016 at 21:48
  • $\begingroup$ 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. $\endgroup$
    – Anonymous
    Commented Oct 30, 2016 at 21:53

1 Answer 1

3
$\begingroup$

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.)

$\endgroup$
4
  • $\begingroup$ That was concise and right to the point. So, Can I define any line as ax+by=1? That would be so convenient. $\endgroup$
    – Stepan
    Commented Oct 30, 2016 at 21:41
  • 2
    $\begingroup$ No, take the non-vertical line given by $y=0$ for example. $\endgroup$ Commented Oct 30, 2016 at 22:09
  • $\begingroup$ It seems like you have reciprocals of x and y and correct formulas are: x =(ce-fb)/(ae-db); y =(cd-af)/(bd-ae); $\endgroup$
    – Stepan
    Commented Nov 1, 2016 at 16:01
  • $\begingroup$ @Stepan You're right. Problem fixed. Thank you. $\endgroup$
    – mfl
    Commented Nov 1, 2016 at 20:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .