Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How find an angle between two lines

edited December 2014 in Questions Posts: 4

Hi gays, I'm realy noob and need you help!
How can i find angle between to lines
PS sorry about my English


  • IgnatzIgnatz Mod
    Posts: 5,396

    If line 1 goes through points (ax1,ay1) and (ax2,ay2), make.
    m1=(ay2-ay1)/(ax2-ax1) --slope of line.

    Do the same for line 2 to calculate m2

    Then the angle A between them is calculated from

    tan(A) = abs((m1-m2)/(1+m1*m2))

  • Or you could define the two vectors along the lines and use the inbuilt angleBetween method. Using Ignatz' notation:

    u = vec2(ax2-ax1,ay2-ay1)
    v = vec2(bx2-bx1,by2-by1)
    a = u:angleBetween(v)

    Or all in one:

    a = vec2(ax2-ax1,ay2-ay1):angleBetween(vec2(bx2-bx1,by2-by1))

    (Look up the documentation to see whether the result is in radians or degrees.)

Sign In or Register to comment.