计算三点形成的角度

double CalcAngle(MyPoint first, MyPoint cen, MyPoint second)
{
    double dx1, dx2, dy1, dy2; 
    double angle; 

    dx1 = first.x - cen.x; 
    dy1 = first.y - cen.y; 

    dx2 = second.x - cen.x; 

    dy2 = second.y - cen.y; 

    double c = (double)sqrt(dx1 * dx1 + dy1 * dy1) * (double)sqrt(dx2 * dx2 + dy2 * dy2); 

    if (c == 0) return -1; 

    angle = (double)acos((dx1 * dx2 + dy1 * dy2) / c); 

    return angle / PAI * 180; 
}

 

posted @ 2016-02-23 16:29  秋月的私语  阅读(1172)  评论(0编辑  收藏  举报