MATLAB: How to find cosine angle known the end points of 2 linesegments

angle between 2 linesegments

There are 2 line segments, known their end points, how can i find angle between them

Best Answer

  • The arguments you pass to dot and norm must be vectors not scalars
    v1 = [1 1]
    v2 = [0 3]
    D = [v1;v2]; %possibly you have something like this
    costheta = dot(D(1, :), D(2, :)) / (norm(D(1, :)) * norm(D(2, :)));
    thetaindegrees = acosd(costheta)