Angle between two Vectors 2D

前端 未结 8 1730
深忆病人
深忆病人 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 17:59

    You have to use the difference in x and y inside of the Atan2 method:

    Math.Atan2(b.Y - a.Y,b.X - a.X);

    Also, I believe this will give you the angle from 0 to the hypotenuse of the triangle you've provided (not entirely sure).

    I'd suggest trying Math.PI - angle.

提交回复
热议问题