7

以下は Android コードです。

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

ここに画像の説明を入力

とがった角を取り除くために、私は使用しています

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

ここに画像の説明を入力

WPFに関しては、次のコードを使用しています。

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);

以下の効果を得ています。

ここに画像の説明を入力

PolyQuadraticBezierSegmentorを使用しないことに注意してくださいPolyBezierSegment不安定になりやすい。これは、折れ線グラフに新しい着信ポイントを追加するたびに、新しく追加されたポイントが、画面に既に描画されている古いパスを変更する傾向があることを意味します。最終的な効果として、折れ線グラフ全体が揺れていることがわかります

WPFで線分を滑らかにする方法を教えてください。使用していますがlineSegment.IsSmoothJoin = true;、まだシャープな角が見られます。Android の CornerPathEffect に相当するものはありますか?

4

1 に答える 1

0

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


Since smoothing is dependent on multiple points in the line I think it will be quite difficult to find a smoothing algorithm that looks reasonable without producing some instability in the leading edge. You can probably reduce the scope of the instability, but only at risk of producing a very odd looking trace.

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

Alternatively you can run the actual data points through an initial spline calculation to multiply the points, then run those points through the spline algo a second time. You'll still have to update the most recent 2m points (where m is the multiplier of the first pass) or the output will look distorted.

About the only other option I can think of is to try to predict a couple of points ahead based on your prior data, which can be difficult even with a fairly regular input. I used this to synthesize Bezier control points for the ends of my curves - I was calculating CPs for all of the points and needed something to use for the end points - and had some interesting times trying to stop the final curve segments from looking horribly deformed.

Oh, one more... don't graph the final curve segment. If you terminate your curve at Pn-1 the curve should stay stable. Draw the final segment in a different style if you must show it at all. Since C-R splines only need +/- 2 known points from the interpolation the segment Pn-2-Pn-1 should be stable enough.

If you don't have code for the C-R algorithm you can do basically the same thing with synthetic Bezier control points. Rather than attempt to describe the process, check out this blog post which gives a fairly good breakdown of the process. This article has code attached which may be useful.

于 2015-12-05T23:30:42.037 に答える