反三角函数角度计算公式:
例如:(atan(x)/pi)*180就可以得到角度了, pi就是圆周率3.1415926..... , 1弧度为180/pi
坐标系中任意3点的夹角计算公式:
而向量夹角的余弦值等于= 向量的乘积/向量模的积。
即向量的夹角公式:cosθ=向量a.向量b/|向量a|×|向量b|
方法一:
#include <iostream>
#include <cmath>
#include <algorithm>
using std::acos; // 反余弦函数
using std::sqrt; // 平方根函数
using namespace std;
float getAngle(float x0,float y0, float x1,float y1, float x2 ,float y2)
{
float angle = 0.0f; // 夹角
// 向量Vector a的(x, y)坐标
float va_x = x1 - x0;
float va_y = y1 - y0;
// 向量b的(x, y)坐标
float vb_x = x2 - x0;
float vb_y = y2 - y0;
float productValue = (va_x * vb_x) + (va_y * vb_y); // 向量的乘积
float va_val = sqrt(va_x * va_x + va_y * va_y); // 向量a的模
float vb_val = sqrt(vb_x * vb_x + vb_y * vb_y); // 向量b的模
float cosValue = produ