如何用条件填充WPF中2条折线之间的区域 [英] How to fill area between 2 polylines in WPF with condition

查看:138
本文介绍了如何用条件填充WPF中2条折线之间的区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一种制图应用程序,其中有2条折线,例如,折线A(在下面的图像中显示为红色线)和折线B(在下面的图像中显示为蓝色线).

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

图表中可能有2个条件:

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.

推荐答案

我从来没有想过,通过填写

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.

假设您用绿色填充了红线下方的整个区域.因此,您将设置一个填充的Path,其Data几何形状是一个封闭的多边形,该多边形由红线的所有点以及视口的两个下角点组成.在该Path上,您可以将Clip属性设置为另一个封闭的多边形几何体,该几何体将包括蓝线中的所有点以及视口的两个上方点.对于红色填充,您可以再次执行相同的操作,但是要使用折线.

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.

祝你好运!

这篇关于如何用条件填充WPF中2条折线之间的区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆