Search code examples
wpfpathgeometry

Programmatically split a path into multiple paths


I have a dynamically generated path whose data is composed of a PathGeometry composed of a PathFigure. This PathFigure contains a bunch of line segments. So the overall path is continuous, composed of straight lines. What is a good approach to split this path into many many different little paths? If you are curious, the reason I need to do this is to achieve a 'path fading away' effect, and there doesn't seem to be another way to do this.

So I want to take a path, and split it into many different little paths, and then I will set the opacity of the first little path to 0, and the last little path to 1, and interpolate for everything in between. Also, I could use this to make the tail of the path small, and interpolate up to the head of the path, which is big. There are many uses - I need a way to do this for my application.


Solution

  • See GradientPath by Charles Petzold it is implemented similar to how you describe and should be easy to tweak if you want to add support for altering the width of the path.