Angle between two Vectors 2D

前端 未结 8 1720
深忆病人
深忆病人 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:04

    if you are looking for the "angle between vectors a and b", you want the delta of the angle for vector a and the angle for vector b:

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

    But the diagram doesn't match "angle between vectors". The answer for the diagram is indeed the previous answer given:

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

提交回复
热议问题