C# 北东地和东北天坐标系转换
一、将正负180的值转成0-360
/// <summary> /// 正负180, 0--->360 /// </summary> /// <param name="p"></param> /// <returns></returns> public static double Conv_k(double p) { while (p > 180) { p = p - 360; } while (p < -180) { p = p + 360; } if(p<=90) { return 90 - p; } if(p>90) { return 360 + (90 - p); } return 0; }
2、将北东地 0--->360,转换为东北天0--->正负180
/// <summary> /// 将北东地 0--->360,转换为东北天0--->正负180 /// </summary> /// <param name="p"></param> /// <returns></returns> public static double Conv_k_rev(double p) { //转换至0-360° while (p > 360) { p = p - 360; } while (p < 0) { p = p + 360; } //转换至±180° if (p <= 270) { return 90 - p; } if (p > 270) { return 360 + (90 - p); } return 0; }