图表:带状线和曲线的交点 [英] Charts: stripline and curve intersection points

查看:80
本文介绍了图表:带状线和曲线的交点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在没有太多数据点的正弦形图形中添加了一条水平带状线。有没有找到x坐标相交的方法?

I've added a horizontal stripline to a sinusoidal type graph which doesn't have many datapoints. Is there a way to find the x-coordinate intersections?

推荐答案

您可以解析地解决它,即,如果数据是从公式中得出的,则可以使用数学来求解交集。

You can either tackle it analytically, i.e. if your data are derived from a formula you can use math to solve the intersection set.

或者您可以在 GDI + 的帮助下获得近似值。

Or you can us an approximation with a little help from GDI+.

正如您所发现的那样,直接在人口稀少的点集中直接使用 DataPoints 是行不通的。

As you have found using the DataPoints directly in a thinly populated set of points will not work well.

但是有一个有趣且简单的解决方法,可以为您创建更多的积分。

But there is an interesting and simple workaround that can create an enlarged set of points for you.

这需要使用展平 GraphicsPath

假设您的值在 List< PointF>点

List<PointF> points = new List<PointF>();
for (int i = 0; i < 10; i++) points.Add(new PointF(i, (float)Math.Sin(i)));

现在,您首先从中创建一个 GraphicsPath

Now you first create a GraphicsPath from it:

using System.Drawing.Drawing2D;
.. 
..
GraphicsPath gp = new GraphicsPath();
gp.AddCurve(points.ToArray());

然后将其展平:

Matrix m = new Matrix();    // identity
gp.Flatten(m, yourFlatness);

这会将 GraphicsPath 一系列曲线(与图表的样条曲线btw相同)到一系列线段 。 平坦度确定直线可能偏离曲线多少。因此,使用的平整度越小(默认值为0.25f),得到的分段就越多。

This changes the GraphicsPath from a series of curves, (which are identical to the Chart's spline curves, btw,) to a series of line segments. The 'flatness' determines how much the lines may deviate from the curve. so, the smaller the flatness you use (default is 0.25f), the more segments you get.

我们从下面以红色显示的10个 DataPoints 开始。用 0.1f 0.01f 0.001f 展平后我们得到 19 55 152 点/线段分别..:

We have started with 10 DataPoints shown below in red. After flattening with 0.1f, 0.01f and 0.001f we get 19, 55 and 152 points/line segments respectively..:

您可以访问它们在 gp.PathPoints 数组中,它将更接近真实的交叉点。添加一些插值,您应该足够接近爵士乐。

You can acces them in the gp.PathPoints array and will get much closer to the real intersections. Add a little interpolation and you should be close enough for jazz..

这篇关于图表:带状线和曲线的交点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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