假设已知笔画墨迹的起始点坐标,触摸点的坐标很容易获取,下面就是找到要删除的墨迹的核心代码!
private bool lineInterCircle(Point ptStart, Point ptEnd, Point ptCenter)//ptCenter目标坐标点 { double eraserRadius = 17; double fDis = Math.Sqrt((ptEnd.X - ptStart.X) * (ptEnd.X - ptStart.X) + (ptEnd.Y - ptStart.Y) * (ptEnd.Y - ptStart.Y)); if (fDis == 0) { // 点重叠,则判断该点群到橡皮擦的距离是否大于圆的半径 double d = Math.Sqrt((double)(Math.Pow(Math.Abs(ptStart.X - ptCenter.X), 2) + Math.Pow(Math.Abs(ptStart.Y - ptCenter.Y), 2))); return (d < eraserRadius) ? true : false; } Point dPoint = new Point(); dPoint.X = (int)((ptEnd.X - ptStart.X) / fDis); dPoint.Y = (int)((ptEnd.Y - ptStart.Y) / fDis); Point ePoint = new Point(); ePoint.X = ptCenter.X - ptStart.X; ePoint.Y = ptCenter.Y - ptStart.Y; double a = ePoint.X * dPoint.X + ePoint.Y * dPoint.Y; double a2 = a * a; double e2 = ePoint.X * ePoint.X + ePoint.Y * ePoint.Y; double r2 = eraserRadius * eraserRadius; if ((r2 - e2 + a2) < 0) { return false; } else { //求交点 double f = Math.Sqrt(r2 - e2 + a2); double t = a - f; if (((t - 0.0) > -0.00001) && (t - fDis) < 0.00001) { return true; } t = a + f; if (((t - 0.0) > -0.00001) && (t - fDis) < 0.00001) { return true; } } return false; }