我有一个由Point2D
组成的数组(它有两个成员x
和y
),例如Point2D[] points
。你可以把这个数组看作x-y图上的一系列点。数组的排序方式是从较小的Point2D.X
到较大的Point2D.X
我的问题很简单:你如何找到点(以及相应的项目索引在这些点之前和之后)是局部最大值/最小值?回想一下,局部max/min在数学上定义为dy/dx=0
所以我的任务是找到那些dy/dx=0
的点。
请注意,极值点可能位于也可能不位于Point2D
数组的正内部,因为图形是平滑曲线,而不是线性分段多段线。一个极值点可以是数组中两点的中点。例如。
是否有任何现有的库/组件已经在C?
以下是我的方法:
public class Point2D
{
public double X;
public double Y;
}
public class PointWithIndex
{
// the extreme point where dy/dx=0
public Point2D ExtremePoints;
// the index of the array for the point that locates right before this ExtremePoints
public int PrevItemIndex;
}
public static List<PointWithIndex> FindLocalExtrema(List<Point2D> xyPoints)
{
// the algorithm to find the max/min points of xyPoints
}
最佳答案
我建议运行一个循环0
关于c# - 计算给定X Y系列的局部最大值/最小值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10116790/