/LinearEquationFromPoints

Algorithm to construct a linear equation from a list with >= 2 points proof of concept

Primary LanguageTypeScriptMIT LicenseMIT

LinearEquationFromPoints

This is a proof of concept demo for an algorithm which converts an array of points >= 2 (x, y) to a linear equation y = x * m + c.


We firstly calculate the slope of each point to its left neighbour (Note that the list must be sorted by x). We can now use this value to construct the c for each point. (c = y - m * x)

We can now take the average value of both and we will get a linear equation which is in theory as close as possible to all of the points in the list.


Demo here