Angle between two Vectors 2D

前端 未结 8 1710
深忆病人
深忆病人 2021-02-05 17:29

I\'m trying to compute the angle between two vectors. I tried this, but it always returns zero:

public double GetAngle(Vector2 a, Vector2 b)
{
double angle = Mat         


        
相关标签:
8条回答
  • 2021-02-05 18:09

    A simple solution should be this:

    Vector2 a_normalized = normalize(a);
    Vector2 b_normalized = normalize(b);
    double angle = arccos(dot(a_normalized,b_normalized));
    

    http://simple.wikipedia.org/wiki/Dot_product

    This is Pseudo-code, because C# is not my world. Sorry

    0 讨论(0)
  • 2021-02-05 18:13

    tan(angle) = opposite/adjascent

    arctan(opposite/adjascent) = angle

    opposite = a.y - b.y

    adjascent = b.x - a.x

    Math.Atan((a.Y - b.Y) / (b.X - a.X));
    
    0 讨论(0)
提交回复
热议问题