1

I need an algorithm to find equation of a line without using division. Given a line by two points on it, with coordinates: $(x_1, y_1),\ (x_2, y_2)$. We can simply get the line equation by the formula:
$$y=y_1+(y_2−y_1)((x−x_1) / (x_2−x_1))$$

But I want to do that without using division. I want to find $y(x_0)$ for the specific $x_0$ value $(x_1<x_0<x_2)$.

Thanks in advance.

LeoTheKub
  • 438
Heghine
  • 265
  • The equation of the line does not require division. Finding a specific $y_0$ given $x_0$ usually does. – André Nicolas Mar 17 '14 at 17:39
  • $\displaystyle{\large\vec{\rm r}\left(\lambda\right) = \vec{r}{1} + \left(\vec{r}{2} - \vec{r}_{1}\right)\lambda,,\quad\lambda\in{\mathbb R}}$. – Felix Marin Mar 17 '14 at 18:53

1 Answers1

0

If you parameterize the line as $L(t)=(tx_{2}+(1-t)x_{1},ty_{2}+(1-t)y_{1})$, then if you take $x_{0}$ the $t^{*}$ such that $L(t^{*})=(x_{0},y_{0})$ is given by $t^{*}=\frac{x_{0}-x_{1}}{x_{2}-x_{1}}$. Note that $c=\frac{1}{x_{2}-x_{1}}$ is known from the outset, therefore $y_{0}(x_{0})=c*(x_{0}-x_{1})*y_{2}+(1-c*(x_{0}-x_{1}))y_{1}$. I am not sure how exactly you define "not using division" but if computing a known constant $c$ at the start of the algorithm is not a problem then this works.

h4nusGT
  • 275
  • Or of course take as an input of the algorithm the points $(x_{1},y_{1}),(x_{2},y_{2}),\frac{1}{x_{2}-x_{1}}$. – h4nusGT Mar 17 '14 at 18:52
  • Here $1/(x_2 - x_1)$ you are using division, the $x_2, x_1$ can be very small floating point numbers, so we can lose accuracy when doing division. – Heghine Mar 18 '14 at 05:57