How to fill area between 2 polylines in WPF with condition

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-03 03:22:26

问题


I am developing a charting application in which there are 2 polylines, say Polyline A (shown as red colour line in below image) and Polyline B (shown as blue colour line in below image).

There can be 2 conditions in the chart:

  • When the red line intersects the blue line from above and then stays below the blue line, I want to fill that area with some color.

  • When the red line intersects the blue line from below and then stays above the blue line, I want to fill that area with some other color.


回答1:


Without ever having done this, i could imagine that you might be able to do what you want without much mathematics by filling a Path and setting its Clip in an appropriate way.

Let's say you fill the entire area below the red line with green. Therefore you would set up a filled Path whose Data geometry is a closed polygon consisting of all the points of the red line plus the two lower corner points of the viewport. On that Path you would set the Clip property to another closed polygon geometry, which would consist of all the points from the blue line plus the two upper points of the viewport. For the red fill you would do the same again, but with exchanged polylines.

The straightforward approach would of course be to find the intersection points, determine the direction of the intersection, create closed polygons from the upper and lower line points plus the appropriate intersection points and fill these polygons according to the intersection direction.

Good luck!



来源:https://stackoverflow.com/questions/11664184/how-to-fill-area-between-2-polylines-in-wpf-with-condition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!