To achieve the smooth curve we can use cubic bezier curves, as shown on the above answer, with the PolyBezierSegment class.
How it works
A cubic Bezier curve is defined by four points: a start point, an end point and two control points.
For every three points in the collection, the first and second points specify the two control points of the curve and the third point specifies the end point. Note that no start point for the curve is specified because start point is the same as the end point of the last segment.
If you want to specify only the start and end points of each segment you need to calculate the control points dynamically, that will depend on the kind of curvature you need.
On the following example I will define 3 points, then I will hardcode the control points to define the curvature, this should be made with an algorithm that calculates the curvature according to your needs.
Note that I am adding the start point to the points collection, although the path figure class needs one point for start position and the PolyBezierSegment class needs a collection with multiples of 3 (2 controls and an end point)
//create 3 positions
Point start = new(50, 50),
mid = new(80, 100),
end = new(200, 150);
Point[] _points = new[]
{
//start of line (and first segment)
start,
//First control point:
new(start.X, start.Y + (mid.Y - start.Y) / 2),
//Second control point:
new(mid.X - (mid.X - start.X) / 2, mid.Y),
//end of first segment and start of second.
mid,
new(mid.X + (end.X - mid.X) / 2, mid.Y),
new(end.X, end.Y - (end.Y - mid.Y) / 2),
end
;
//Create the segment connectors
PathGeometry connectorGeometry = new()
{
Figures = new PathFigureCollection()
{
new PathFigure()
{
//define the start of the smooth line
StartPoint = _points[0],
//define the coordinates of the smooth line
Segments = new PathSegmentCollection()
{
new PolyBezierSegment(
//in this example I added the start to the collection,
//so we skip the first coordinate already used on "StartPoint"
points: _points.Skip(1),
isStroked: true)
}
}
}
};
Path smoothCurve = new()
{
Stroke = Brushes.Black,
StrokeThickness = 3,
Data = connectorGeometry
};
Graph.Children.Add(smoothCurve);
Result:
