【OpenCv/EmguCv】指针式仪表读数(二)
程序员文章站
2024-03-18 22:50:58
...
1. 计算偏移角度
计算三个点的夹角:以仪表圆心为中心,指针的一个端点和参考点为另外两个点计算三个点所组成的两条线段的夹角α
public double Angle(Point cen, Point first, Point second)
{
const double M_PI = 3.1415926535897;
double ma_x = first.X - cen.X;
double ma_y = first.Y - cen.Y;
double mb_x = second.X - cen.X;
double mb_y = second.Y - cen.Y;
double v1 = (ma_x * mb_x) + (ma_y * mb_y);
double ma_val = Math.Sqrt(ma_x * ma_x + ma_y * ma_y);
double mb_val = Math.Sqrt(mb_x * mb_x + mb_y * mb_y);
double cosM = v1 / (ma_val * mb_val);
double angleAMB = Math.Acos(cosM) * 180 / M_PI;
return angleAMB;
}
2. 计算示数
value = max*α/360(0<α<180);
value = max*(360-α)/360(180<α<360);
private double getValue()
{
double angle = Angle(center, new Point(center.X, 0), p);
if (p.X < center.X)
{
angle = 360 - angle;
}
return ((angle/360)*60;
}
上一篇: 基于JS的2048小游戏详解
下一篇: 面试官问你:“MongoDB你用过吗?”