Getting angle between 2 lines in swift [duplicate]

If you have two points, (x0, y0) and (x1, y1), then the angle of the line joining them (relative to the X axis) is given by:

theta = atan2((y1 - y0), (x1 - x0))

The angle between a line, for reference, let's call this A, defined by two points p1=(x1,y1),p2=(x2, y2) and the x-axis is related to finding the slope/ gradient of the line, A.

# To solve a problem you sometimes have to simplify it and then work up to the full solution"

Let's start by obtaining the gradient of the line A.

The gradient of line A:

slope = (y2 - y1)/(x2 - x1)

for a straight line, that makes an angle theta with the x-axis tan(theta) = slope = (change in y) / (change in x)

Therefore, theta = tan_inverse (slope)

theta = atan(slope)