用两点c#计算角度

时间:2015-08-26 14:46:33

标签: c# draw angle

我有一条线(DrawLine-Event)带点(a,b)(c,d),现在我想计算它的角度,但我不知道怎么做。

我试过这样:

double atan = ((d - b) / c - a)) * Math.PI / 180;
double solution = Math.Atan(atan);
int angle = Convert.ToInt32(Math.Round(solution * 180 / Math.PI));

1 个答案:

答案 0 :(得分:1)

您可以使用Vector.AngleBetween Method获取角度

private Double angleBetweenExample()
{
    Vector vector1 = new Vector(20, 30);
    Vector vector2 = new Vector(45, 70);
    Double angleBetween;

    // angleBetween is approximately equal to 0.9548
    angleBetween = Vector.AngleBetween(vector1, vector2);

    return angleBetween;

}