Given two points P(a, b) and Q(c, d) in the coordinate plane, find the equation of the line passing through both the points.
Example 1:
Input: P = (3, 2)
Q = (2, 6)
Output: 4x+1y=14
Explaination: Using the formula to get
line equation from two points we can
get it.
Example 2:
Input: P = (3, 2)
Q = (5, 7)
Output: 5x-2y=11
Explaination: If we use the formula to
get line equation from two points we
get this equation.
Your Task:
You do not need to read input or print anything. Your task is to complete the function getLine() which takes the values a, b, c and d as input parameters and returns a string which represents the equation.
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ a, b, c, d ≤ 10^{5}

Source: geeksforgeeks | Difficulty: EASY
Tags: Geometry

Starter code: #User function Template for python3

class Solution:
    def getLine(self, a, b, c, d):
        # code here

Solutions:
class Solution:

	def getLine(self, a, b, c, d):
		x = d - b
		y = c - a
		z = (d - b) * a - (c - a) * b
		if x > 0:
			if y > 0:
				return str(x) + 'x-' + str(y) + 'y=' + str(z)
			return str(x) + 'x+' + str(abs(y)) + 'y=' + str(z)
		if y > 0:
			return str(x) + 'x-' + str(y) + 'y=' + str(z)
		return str(x) + 'x+' + str(abs(y)) + 'y=' + str(z)


class Solution:

	def getLine(self, a, b, c, d):
		g = d - b
		h = a - c
		j = d * (a - c) - c * (b - d)
		t = ''
		t += str(g) + 'x'
		if h > 0:
			t += '+' + str(h) + 'y'
		else:
			t += str(h) + 'y'
		t += '=' + str(j)
		return t


class Solution:

	def getLine(self, a, b, c, d):
		if a != c:
			x1 = d - b
			y1 = a - c
			t = b * (a - c) + a * (d - b)
			s = str(x1) + 'x'
			if y1 > 0:
				s += '+'
			s += str(y1) + 'y' + '=' + str(t)
			return s
		elif b != d:
			s = 'x=' + str(a)
			return s
		else:
			return '0x+0y=0'
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(a, b) = [int(x) for x in input().split()]
		(c, d) = [int(x) for x in input().split()]
		ob = Solution()
		print(ob.getLine(a, b, c, d))


class Solution:

	def getLine(self, a, b, c, d):
		f = d - b
		g = c - a
		z = -g
		if g < 0:
			k = '+'
		else:
			k = ''
		p = -(b * g - a * f)
		return str(f) + 'x' + k + str(z) + 'y' + '=' + str(p)


class Solution:

	def getLine(self, a, b, c, d):
		x1 = a
		x2 = c
		y1 = b
		y2 = d
		c1 = y2 - y1
		c2 = x1 - x2
		c = x1 * (y2 - y1) - y1 * (x2 - x1)
		if c2 >= 0:
			return str(c1) + 'x+' + str(abs(c2)) + 'y=' + str(c)
		else:
			return str(c1) + 'x-' + str(abs(c2)) + 'y=' + str(c)