Given the two coordinate points located on each line, how can i find the angle between both the lines?

Suppose the two point of line 1 are : (x11,y11) and (x12,y12)

similarly the two point of line 2 are : (x21,y21) and (x22,y22)

now as we know from vector algebra we can express the first line vectorially as : (x12-x11)i + (y12-y11) j

and the second line as : (x22-x21)i + (y22-y21) j

Now We have two vectors and we can easily calculate the angle between them by dot product:

let A = (x12-x11)i + (y12-y11) j

```
B = (x22-x21)i + (y22-y21) j
```

we know dot product of two vectors A.B = Ax * Bx + Ay* By + Az*Bz = |A| * |B| * cos(angle between A and B)

also we know that magnitude of A = |A| = sqrt(Ax^2 + Ay^2)

magnitude of B = |B| = sqrt(Bx^2 + By^2)

You have all the data here so you can easily compute the angle.

Some Reference :

Also if you want you can follow another process which computes angle using slopes. As given here

#define PI 3.14159265

```
m1 = (y12 - y11) / (x12 - x11); // tan(A)
A = atan(m1) * 180 / PI;
```

A = angle between x-axis and line 1

```
m2 = (y22 - y21) / (x22 - x21); // tan(B)
B = atan(m2) * 180 / PI;
```

B = angle between x-axis and line 2

Angle between line 1 and line 2 = A - B

Include math.h and then use the following formula:

atan((y2-y1)/(x2-x1))

This will give you desired angle in radians.

Similarly find the same for the other line and subtract for the angle between two lines.

Use this formula to convert into degrees: PI radian = 180 degrees

#include<stdio.h>

#include<math.h>

int main()

{

int x[4],y[4];

float m[2],k,a;

printf(“enter the coordinates of 1st point on line 1 “);

scanf(”%d%d”,&x[1],&y[1]);

printf(“enter the coordinates of 2nd point on line 1 “);

scanf(”%d%d”,&x[2],&y[2]);

printf(“enter the coordinate of 1st point on line 2 “);

scanf(”%d%d”,&x[3],&y[3]);

printf(“enter the coordinate of 2nd point on line 2 “);

scanf(”%d%d”,&x[4],&y[4]);

```
m[1]=(y[2]-y[1])/(x[2]-x[1]); //slope of line1
m[2]=(y[4]-y[3])/(x[4]-x[3]); //slope of line2
k=(m[1]-m[2])/(1+m[1]*m[2]);
if(k<0)
{
k=-k;
}
a=57.692*atan(k); //1rad=57.692degree
printf("angle between these two lines in degree is %f",a);
}
```

Please re-edit this answer, not looking good.

“Given the two coordinate points located on each line”

angle between two lines = difference between their slopes.

Fixed the format.