Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Canvas>
- <Path x:Name="pathMain" Stroke="Blue" StrokeThickness="2"/>
- </Canvas>
- public PolyLineSegment DrawArrow(Point a, Point b)
- {
- double HeadWidth = 10; // Ширина между ребрами стрелки
- double HeadHeight = 5; // Длина ребер стрелки
- double X1 = a.X;
- double Y1 = a.Y;
- double X2 = b.X;
- double Y2 = b.Y;
- double theta = Math.Atan2(Y1 - Y2, X1 - X2);
- double sint = Math.Sin(theta);
- double cost = Math.Cos(theta);
- Point pt3 = new Point(
- X2 + (HeadWidth * cost - HeadHeight * sint),
- Y2 + (HeadWidth * sint + HeadHeight * cost));
- Point pt4 = new Point(
- X2 + (HeadWidth * cost + HeadHeight * sint),
- Y2 - (HeadHeight * cost - HeadWidth * sint));
- PolyLineSegment arrow = new PolyLineSegment();
- arrow.Points.Add(b);
- arrow.Points.Add(pt3);
- arrow.Points.Add(pt4);
- arrow.Points.Add(b);
- return arrow;
- }
- private void DrawLine(MouseEventArgs e)
- {
- Point endPoint = e.GetPosition(this);
- PathFigure pathFigure = new PathFigure
- {
- StartPoint = new Point(800, 500),
- IsClosed = false
- };
- //Кривая Безье
- Vector vector = endPoint - pathFigure.StartPoint;
- Point point1 = new Point(pathFigure.StartPoint.X + vector.X / 2, pathFigure.StartPoint.Y);
- Point point2 = new Point(pathFigure.StartPoint.X + vector.X / 1.5, pathFigure.StartPoint.Y + vector.Y/ 0.95);
- BezierSegment curve = new BezierSegment(point1, point2, endPoint, true);
- PolyLineSegment arrow = DrawArrow(pathFigure.StartPoint, endPoint);
- PathGeometry path = new PathGeometry();
- path.Figures.Add(pathFigure);
- pathFigure.Segments.Add(curve);
- pathFigure.Segments.Add(arrow);
- pathMain.Data = path;
- }
- var startPoint = pathFigure.StartPoint;
- //Кривая Безье
- Vector vector = endPoint - startPoint;
- Point point1 = new Point(startPoint.X + 3 * vector.X / 8, startPoint.Y + 1 * vector.Y / 8);
- Point point2 = new Point(startPoint.X + 5 * vector.X / 8, startPoint.Y + 7 * vector.Y / 8);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement