Equation for line between three points

3.7k Views Asked by At

I have three points: $(0,0),(2,1),(3,2)$ and I get a graph like this:

Graph of points (0,0)(2,1)(3,2)

Is there a formula to draw this graph with the line (or two lines meeting in the middle, if you prefer- but definitely not a curve) continuing straight/linearly in both directions indefinitely?

I've hacked together an excel formula that uses a "IF" but it seems inelegant.

2

There are 2 best solutions below

10
On

Think of the function of a generic parabola

$y^2=ax+by+c$

This is identified by three numbers. You have three points, if they don't lie on the same line (and they don't), you can use those points to determine the equation of the parabola passing through them.

First step.

Substitute each of your point in the parabola equation above:

$0 = c$

$1 = 2a+1b$

$4=3a+2b$

Second step.

Easily solve the system above to get the values a=-2 and b=5.

Therefore, one curve you are looking for is: $y^2=-2x+5y$.

PS. Also remember the following: given 3 points (not lying on the same line) there exists a unique circle passing through these points. So in case you want a circle instead, it's also possible to find the equation for that.

EDIT: Based on the comments I seem to understand you just want each of the two lines you have continuing indefinitely. In this case you have to compute the slope of each of them (that is the lines passing through (0,0) and (2,1) of slope 1/2, and the line passing through (2,1) and (3,2) of slope 1) and define a piecewise function something like:

$y(x)=\frac{1}{2}x$, for x<=2

$y(x)=x-1$ for x>2

This because your lines intersect in (4,2).

0
On

The simplest way to represent your function is indeed with an if:

For $x \leq 2$, you have $f(x)=\frac{x}{2}$, and for $x \geq 2$, you have $f(x)=x-1$. I assume here that the unit of a square in your graph is 0.5 and that the 3 dots represent the 3 points you are talking about (difference with @Chickenmancer)

Then $$f(x)=\left\{\begin{array}{cc} \dfrac{x}{2}, &\text{for } x\leq 2,\\ x-1, &\text{for } x>2.\end{array}\right. $$

If you don't want this if (or this disjunction of case), you can see that your function is actually the maximum of these 2 affine functions.

Therefore $f(x)=\max(\frac{x}{2}, x-1)$.

And we can "simplify" this expression using the fact that $\max(a,b)=\frac{|a-b|}{2}+\frac{a+b}{2}$:

$$\boxed{f(x)=\dfrac{|x-2|}{4}+\dfrac{3x-2}{4}}$$