# degree finding

how can i find the degree of two lines if i am given the two lines connected with each other ,their coordinations also given?
pls give me the logic
###### Who is Participating?

IT Services ConsultantCommented:
0

Commented:
There are two lines: one from (x1,y1) to (x2,y2) and one from (x3,y3) to (x4,y4)

dx1 = x2 - x1
dy1 = y2 - y1
dx2 = x4 - x3
dy2 = y4 - y3

mag1 = sqrt(dx1*dx1 + dy1 * dy1)    ; magnitude of first segment
mag2 = sqrt(dx2*dx2 + dy2 * dy2)     ; magnitude of second segment
dp = (dx1 * dx2 + dy1 * dy2) / (mag1 * mag2)     ; dot product of two difference vectors, normalized
; now, dp = cosine(angle) = sin(PI/2 - angle).
comp = arcsin(dp)  ; which == PI/2 - angle
angle = PI/2 - comp

angle is now the angle between the two lines, in terms of radians
angle_deg = angle * 180 / PI

I
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.