The Task
Write a function L() that takes two Tuple arguments of coordinates in the form (x, y), and returns their respective linear function in the form (a, c), where a is the co-efficent of the x term and c is the y-intercept.
You can assume that the input will not be a line perpendicular the the x axis, and that the two inputs are separate points.
Scoring
This is Code Golf: shortest program wins.
Please Note: No use of any mathematical functions apart from basic operators (+,-,/,*).
Example
Here is my un-golfed solution in Python.
def L(Point1, Point2):
x = 0
y = 1
Gradient = (float(Point1[y]) - float(Point2[y])) / (float(Point1[x]) - float(Point2[x]))
YIntercept = Point1[y] - Gradient * Point1[x]
return (Gradient, YIntercept)
Output:
>>> L( (0,0) , (1,1) )
(1.0, 0.0)
>>> L( (0,0) , (2,1) )
(0.5, 0.0)
>>> L( (0,0) , (7,1) )
(0.14285714285714285, 0.0)
>>> L( (10,22.5) , (5,12.5) )
(2.0, 2.5)
L( (0,0) , (0,1) )
? \$\endgroup\$L((0,0),(0,0))
? \$\endgroup\$