问题
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?
回答1:
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:
- 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: Isn't is remarkable how those lines add a visible structure to the chaos?
Here is an example with 100 random points.
来源:https://stackoverflow.com/questions/45909054/ms-chart-connecting-all-datapoints-without-lines-crossing