您的位置:首页 > 其它

求两个向量夹角

2009-09-03 09:37 316 查看
/******************************************

  输入:

  3点坐标值

 返回:

  (first-cen)和(second-cen)两个向量的角度;

******************************************/ 

 

float CImageDoc::CalcAngle(CPoint cen,CPoint first,CPoint second)
{
 float dx1,dx2,dy1,dy2;
 float angle;

 dx1 = first.x - cen.x;
 dx2 = second.x - cen.x;
 dy1 = first.y - cen.y;
 dy2 = second.y - cen.y;

 float c=(float)sqrt((dx1*dx1+dy1*dy1)*(dx2*dx2+dy2*dy2));
 if(c==0) return -1;
 angle = (float)asin((dx1*dy2-dy1*dx2)/c);
 angle=angle*180/PI;
 return angle;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  float c