向量夹角公式:
cosα = AB / (|A||B|)
设A(x1,y1),B(x2,y2);
cosα =(x1x2 + y1y2) / sqrt( (x1^2 + y1^2) * (x2^2 + y2^2) )
代码实现(c++):
#include <math.h> //Calcucate angle between vector A and B//返回角度; return degreeint CalculateVectorAngle(int x1, int y1, int x2, int y2){ //acos return radian,we should transform it into degree return acos((x1*x2 + y1*y2) / sqrt((x1*x1 + y1*y1)*(x2*x2 + y2*y2)) * 180 / 3.14;}
原文链接: https://www.cnblogs.com/little-ant/archive/2011/05/27/2060377.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/26273
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!