# angle and coordinator calculate from two points forming a line

Two points are given: $$A (x_1, y_1)$$ and $$B (x_2, y_2)$$. These points form a line.

At point $$B$$ is the end of the line. I need to calculate the angle that is shown in the figure and also the position of the new point lying on this line that is 5 cm from point $$B$$. see here

Hint: $$\varphi=\arctan\bigg(\frac{\Delta y}{\Delta x}\bigg)=\arctan\bigg(\frac{y_1-y_2}{x_1-x_2}\bigg)$$ or $$\varphi=\pi-\arctan\bigg(\frac{y_1-y_2}{x_1-x_2}\bigg)$$ why?

I often use four-quadrant compass directions for both "inverse" and "forward".

The inverse from x2,y2 to x1,y1 is a direction of InvTan((x1 - x2) / (y1 - y2)). If (x1 - x2) is positive then the calculation relates to East else West. If (y1 - y2) is positive then the calculation relates to North else South. The expected direction in the example is N_angle_W .

The inverse also has a distance of the Square Root of ((x1 - x2)^2 + (y1 - y2)^2) .

The North coordinate, or y-coordinate, of the forward point is y2 +/- (Cos(direction) * distance). If the direction is noted as North then the operation is positive otherwise negative if South. The distance, of course, is the distance from x2,y2 to the forward point.

The East coordinate, or x-coordinate, of the forward point is x2 +/- Sin(direction * distance). If the direction is noted as East then the operation is positive otherwise negative if West. And the distance is the distance from x2,y2 to the forward point.

To forward a point from x1,y1, as in the direction of x2,y2, then the previous direction of N_angle_W must be changed to S_angle_E .

dx, dy = (x2 - x1), (y2 - y1)

It's length is

len = sqrt(dx*dx + dy*dy)

Unit direction vector is

udx, udy = dx/len, dy/len

Point at distance D from the end (this is head point of arrow, as I understand):

x3, y3 = x2 - D * udx, y2 - D * udy

do you need something else to build arrow?