根據已知的二維數組查找峯值,用於等高線、等值線以及雲圖的繪製。
什麼是峯值:根據個人理解,當前座標對應的數值均大於或等於周邊相鄰的所有值,即可認爲當前座標對應的值爲峯值。
閒話少敘,以圖爲證:
根據輸入的81個值計算後的峯值如下(共5個):
核心代碼
//liangxin 2020-04-19
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
double curValue = array[i][j];
double p1,p2,p3,p4,p5,p6,p7,p8;
if(curValue > p1 &&
curValue > p2 &&
curValue > p3 &&
curValue > p4 &&
curValue > p5 &&
curValue > p6 &&
curValue > p7 &&
curValue > p8) {}