private void UpdateLine()
{
int dotTime = 0;
int intervalLen = (int)model.CurrentDrawingAttributes.Width*2;//步长
double lineLen = Math.Sqrt(Math.Pow(PointStart.X - PointEnd.X, 2) + Math.Pow(PointStart.Y - PointEnd.Y, 2));//线的长度
Point currentPoint = new Point(PointStart.X, PointStart.Y);
double relativaRate = Math.Abs(PointEnd.Y - PointStart.Y) * 1.0 / Math.Abs(PointEnd.X - PointStart.X);
double angle = Math.Atan(relativaRate) * 180 / Math.PI;//直线的角度大小,无需考虑正负
int xOrientation = PointEnd.X > PointStart.X ? 1 : -1;//判断新生成点的X轴方向
int yOrientation = PointEnd.Y > PointStart.Y ? 1 : -1;
if (lineLen < intervalLen)
{
List<Point> pL = new List<Point>();
pL.Add(PointStart);
pL.Add(PointEnd);
this.inkContent.Children.Clear();
StylusPointCollection spc = new StylusPointCollection(pL);//相邻两点作为一个笔画
Stroke stroke = new Stroke(spc, model.CurrentDrawingAttributes);
this.inkContent.Strokes.Add(stroke);
return;
}
while (dotTime * intervalLen < lineLen)
{
double x = currentPoint.X + dotTime * intervalLen * Math.Cos(angle * Math.PI / 180) * xOrientation;
double y = currentPoint.Y + dotTime * intervalLen * Math.Sin(angle * Math.PI / 180) * yOrientation;
List<Point> pL = new List<Point>();
pL.Add(new Point(x, y));
x += intervalLen * Math.Cos(angle * Math.PI / 180) * xOrientation;
y += intervalLen * Math.Sin(angle * Math.PI / 180) * yOrientation;
pL.Add(new Point(x, y));
this.inkContent.Children.Clear();
StylusPointCollection spc = new StylusPointCollection(pL);//相邻两点作为一个笔画
Stroke stroke = new Stroke(spc, model.CurrentDrawingAttributes);
this.inkContent.Strokes.Add(stroke);
dotTime+=2;
}
}