在我的程序中,用户可以在大型显示器上与LASER指针进行交互,LASER将通过在其周围做一个圆圈来执行打开文件等操作。
我的代码正在检测画一个圆圈,我想预测用户在连续移动期间何时开始制作这个圆圈。我想找到用户开始制作圆圈的时间和这个圆圈的起点。
Bitmap b = new Bitmap(pictureBox1.Image);
Rectangle a = (Rectangle)r;
global.PointX[global.LastIndex] = a.Location.X;
global.PointY[global.LastIndex] = a.Location.Y;
global.LastIndex++;
Pen pen1 = new Pen(Color.FromArgb(160, 255, 160), 3);
Graphics g2 = Graphics.FromImage(b);
pen1 = new Pen(color, 3);
SolidBrush b5 = new SolidBrush(color);
Font f = new Font(Font, FontStyle.Bold);
g2.DrawString("o", f, b5, a.Location);
g2.Dispose();
pictureBox1.Image = (System.Drawing.Image)b;
if (global.LastIndex > 1)
{
if (Math.Sqrt(Math.Pow(global.PointX[global.LastIndex - 1] - global.PointX[0], 2) + Math.Pow(global.PointY[global.LastIndex - 1] - global.PointY[0], 2)) < Math.Sqrt(Math.Pow(global.PointX[global.LastIndex - 2] - global.PointX[0], 2) + Math.Pow(global.PointY[global.LastIndex - 2] - global.PointY[0], 2)))
{
global.CloseToBeCircle = true;
}
global.angle[global.LastIndex] = System.Math.Atan2(global.PointY[global.LastIndex - 2] - global.PointY[global.LastIndex - 1], global.PointX[global.LastIndex - 2] - global.PointX[global.LastIndex - 1]) * 180 / System.Math.PI;
if (global.angle[global.LastIndex - 1] < 0)
global.angle[global.LastIndex - 1] += 360;
if (global.angle[global.LastIndex - 1] > 270 && global.angle[global.LastIndex - 2] < 90)
{
global.angle[global.LastIndex - 2] += 360;
}
else if (global.angle[global.LastIndex - 2] > 270 && global.angle[global.LastIndex - 1] < 90)
{
global.angle[global.LastIndex - 1] += 360;
}
if (global.angle[global.LastIndex - 1] - global.angle[global.LastIndex - 2] > 0)
{
global.IsPositive[global.PositiveIndex++] = true;
}
else if (global.angle[global.LastIndex - 1] - global.angle[global.LastIndex - 2] < 0)
global.IsNegative[global.NegativeIndex++] = true;
//if (global.IsPositive[15] == true || global.IsNegative[15] == true)
if (global.CloseToBeCircle)
{
if ((global.PositiveIndex > global.NegativeIndex && global.NegativeIndex == 0) || (global.NegativeIndex > global.PositiveIndex && global.PositiveIndex == 0))
{
if (Math.Pow(global.PointX[global.LastIndex - 1] - global.PointX[0], 2) <= 25 || Math.Pow(global.PointY[global.LastIndex - 1] - global.PointY[0], 2) <= 25)
{
flush();
this.Invoke((MethodInvoker)delegate
{
MessageBox.Show("Circle");
});
}
}
}