How to get Point.X at a Point.Y on a FlattenPathGeometry - WPF

369 Views Asked by At

I have a "FlattenedPathGeometry" and I want to be able to get a specific point.X from the path based on a specific Point.Y

Basically I just need the X value at any given Y.

Thanks in advance for any help.

1

There are 1 best solutions below

1
On

GetFlattenedPathGeometry gives you back a polygonal so basically you have to consider loop all the points and calculating the minimum distance to your point. If you can make any assumption on the Geometry shape or your point, you can speed up the search.

For example if the path is very long, you can speed up by intersecting the shape with a circle/square centered in your point. This limit the number of points of the shape to test but be careful that the intersection method is very expensive. You'll have to measure the performances with a stopwatch to understand what's better in your case.