Angle between two vectors or two lines

You can easily transform lines into vectors by substracting the endpoint minus the startpoint of the line.

Let’s say you have two lines with endpoints L1(X1,X2), L2(X3,X4), where:

X1 = (x1,y1)     X3 = (x3,y3)

X2 = (x2,y2)    X4 = (x4,y4)

So to transform the two lines into vectors, you must substract the endpoints this way:

u = (x2-x1, y2-y1)

v = (x4-x3, y4-y3)

The formula that will help you obtain the angle between these two lines is:
Ɵ = cos-1(| u·v |)/(√u12+u22 * √v12+v22)

This formula can easily be translated to n dimensions.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: