How to smooth a WPF path line segment

Below is the Android code.

path.moveTo(xx, yy); for (...) { path.lineTo(xx, yy); } canvas.drawPath(this.path, paint); 

enter image description here

To remove a sharp angle , I use

 final CornerPathEffect cornerPathEffect = new CornerPathEffect(50); paint.setPathEffect(cornerPathEffect); 

enter image description here

When WPF comes in, I use the following code.

 PathFigure pathFigure = new PathFigure(); pathFigure.StartPoint = new Point(xx, yy); for (...) { LineSegment lineSegment = new LineSegment(new Point(xx, yy), true); lineSegment.IsSmoothJoin = true; pathFigure.Segments.Add(lineSegment); } PathGeometry pathGeometry = new PathGeometry(new PathFigure[] { pathFigure }); drawingContext.DrawGeometry(null, new Pen(Brushes.White, 3), pathGeometry); 

I get the following effect.

enter image description here

Please note that I avoid using PolyQuadraticBezierSegment or PolyBezierSegment . He seeks to become unstable . This means that whenever I add a new incoming point to the line graph, the newly added point will tend to change the old path that is already drawn on the screen. As a final effect, you can watch the whole line graph shaking

Can I find out in WPF how I can flatten a line segment? Although I used lineSegment.IsSmoothJoin = true; , I can still see a sharp angle. Can I have something equivalent to Android CornerPathEffect? A.

+7
source share
1 answer

I know zombie stream. You probably already solved this problem, but here are my thoughts years after the fact ...


Since anti-aliasing depends on several points in a row, I think it will be quite difficult to find a anti-aliasing algorithm that looks reasonable without creating some instability in the leading edge. You can probably reduce the instability, but only run the risk of creating a very strange footprint.

The first option would be to use a spline algorithm that limits projection artifacts. For example, the Catmull-Rom algorithm uses two known points on each side of a curve segment, interpolated. You can synthesize two additional points at each end of the curve or simply draw the first segment of the curve as a straight line. This will give a straight line as the last segment plus a curve from the second to the last segment, which should change very little, if at all when adding another point.

Alternatively, you can run the actual data points through the initial spline calculation to multiply the points, and then run these points through the spline algo a second time. You still have to update the last 2m points (where m is the first-pass multiplier), or the result will be distorted.

The only other possibility that I can think of is to try to predict a couple of points ahead based on your previous data, which can be difficult even with fairly regular input. I used this to synthesize Bezier control points for the ends of my curves β€” I calculated the CP for all points and needed something that could be used for the end points β€” and had some interesting points trying to stop the end segments of the curve from distorting badly deformed.

Oh, more ... don't draw the final segment of the curve. If you complete your curve at P n-1 , the curve should remain stable. Draw the final segment in a different style, if you should show it at all. Since CR splines require only +/- 2 known interpolation points, the segment P n-2 -P n-1 should be fairly stable.

If you do not have code for the CR algorithm, you can do basically the same with BΓ©zier synthetic control points. Instead of trying to describe the process, check out this blog post , which gives a pretty good breakdown of the process. This article has some code that may be helpful.

0
source

All Articles