一、一点到原点的距离,pt(x,y)
Vector2f v1(x,y); float res1= v1.norm(); // 等于 sqrt(x^2+y^2) , 即距离 float res2 = v1.squaredNorm(); // (x^2+y^2)
二、两个点之间的距离
CPoint pt1(10, 10), pt2(5, 5); Vector2f v4(pt1.x, pt1.y), v5(pt2.x, pt2.y); float len = (v4 - v5).norm();
三、两个向量之间的夹角
Vector2f v1,Vector2f v2; double cosValNew=v1.dot(v2) /(v1.norm()*v2.norm()); //角度cos值 double angleNew = acos(cosValNew) * 180 / M_PI; //弧度角
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/177271.html原文链接:https://javaforall.net
