MS Chart连接所有数据点而无线交叉 [英] MS Chart connecting all datapoints without lines crossing
问题描述
我在MS图表中有数据点,我想将所有这些数据点都用线连接,其中没有线彼此交叉。每个数据点都将连接到另外两个数据点。
I have datapoints in a MS chart and I would like to connect all these datapoints with lines, where none of the lines cross each other. Each datapoint will be connected to 2 other datapoints.
该图应该看起来像一个闭环,非常重要的一点是,没有线可以交叉。
The plot should look like a closed loop, it is very important that there will be no lines that cross on top of another.
有一种简单的方法可以实现吗?
Is there an easy way to achieve this?
推荐答案
好吧,我错了:实际上并不那么难,除非有人想要比您提供的限制更多的限制。这是一种应该起作用的雷达波束方法:
OK, I misspoke: It actually is not that hard, that is unless one wants more restrictions than what you gave. Here is a radar-beam method that ought to work:
- 让我们从点列表开始 li>
- 由此创建一个
List< Tuple< PointF,float,float>>
- 然后我们找到最小和最大x和y值,并从中找到中心点
c
- 接下来,我们分别填充每个Tuple的两个浮点计算每个点到中心的角度和距离
c
- 最后,我们先按角度排序,然后按距离排序
- 现在,我们可以遍历列表并从中创建
DataPoints
,然后将其添加到我们的系列
中。 - 为结束循环,我们在末尾再次添加了第一个
DataPoint
。
- Let's start with a list of points
- From it we create a
List<Tuple<PointF, float, float>>
- Then we find the minimum and maximum x and y values and from these the center point
c
- Next we fill each Tuple's two floats by calculating the angle and the distance between each point and the center
c
- Finally we order by angle and then by distance
- Now we can traverse the list and create
DataPoints
from it we add to ourSeries
. - To close the loop we add the first
DataPoint
again at the end.
这没有任何交叉,但我相信某些结果会比手工制作的解决方案难看。实际上,大多数示例看起来像是爆炸;-)
This connects without any crossings but I believe some results will look uglier than what a hand-crafted solution would be. In fact most examples will look like an explosion ;-)
OTOH:这些线条如何为混乱添加可见结构并不引人注目吗?
OTOH: Isn't is remarkable how those lines add a visible structure to the chaos?
下面是一个具有100个随机点的示例。
Here is an example with 100 random points.
这篇关于MS Chart连接所有数据点而无线交叉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!