-
-
Save krk/832ecef92193dbdcb27047ddd186d2f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private PointCollection GetBezierPoints(PointCollection pts, double tension) { | |
PointCollection ret = new PointCollection(); | |
for (int i = 0; i < pts.Count; i++) { | |
// for first point append as is. | |
if (i == 0) { | |
ret.Add(pts[0]); | |
continue; | |
} | |
// for each point except first and last get B1, B2. next point. | |
// Last point do not have a next point. | |
ret.Add(GetB1(pts, i - 1, tension)); | |
ret.Add(GetB2(pts, i - 1, tension)); | |
ret.Add(pts[i]); | |
} | |
return ret; | |
} | |
// To use the PointCollection returned from GetBezierPoints method in Silverlight, we need to build a Path with BezierSegments in it. | |
private PathFigure GetBezierSegments(PointCollection pts, double tension) { | |
PathFigure ret = new PathFigure(); | |
ret.Segments.Clear(); | |
ret.IsClosed = false; | |
var bzPoints = GetBezierPoints(_projectedPoints, tension); | |
// First point is the starting point. | |
ret.StartPoint = bzPoints[0]; | |
for (int i = 1; i < bzPoints.Count; i += 3) { | |
ret.Segments.Add(new BezierSegment() { | |
Point1 = bzPoints[i], // B1 control point. | |
Point2 = bzPoints[i + 1], // B2 control point. | |
Point3 = bzPoints[i + 2] // P2 start / end point. | |
}); | |
} | |
return ret; | |
} | |
// And use this PathFigure in the MapBezier as: | |
// Create a new PathGeometry. | |
var pGeo = new PathGeometry(); | |
// Add the Bezier PathFigure to the PathGeometry. | |
pGeo.Figures.Add(GetBezierSegments(_projectedPoints, Tension)); | |
// Set data of the Path to the created PathGeometry. | |
((Path) EncapsulatedShape).Data = pGeo; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment