【问题标题】:Convert lat, long to x, y on Mollweide在 Mollweide 上将 lat, long 转换为 x, y
【发布时间】:2021-10-16 19:29:23
【问题描述】:

我已尝试按照here 的说明进行操作,但与this 站点相比,我得到了疯狂的结果。

这是我的代码。

#include <cmath>

double solveNR(double latitude, double epsilon) {
  if (abs(latitude) == M_PI / 2) {
    return latitude;
  }

  double theta = latitude;
  while (true) {
    double nextTheta = theta - (2 * theta * std::sin(2 * theta) - M_PI * std::sin(latitude)) / (2 + 2 * std::cos(2 * theta));
    if (abs(theta - nextTheta) < epsilon) {
      break;
    }
    theta = nextTheta;
  }
  return theta;
}

void convertToXY(double radius, double latitude, double longitude, double* x, double* y) {

  latitude = latitude * M_PI / 180;
  longitude = longitude * M_PI / 180;
  double longitudeZero = 0 * M_PI / 180;
  double theta = solveNR(latitude, 1);

  *x = radius * 2 * sqrt(2) * (longitude - longitudeZero) * std::cos(theta) / M_PI;
  *y = radius * sqrt(2) * std::sin(theta);
}

例如,

180 经度 = 21

90 纬度 = 8.1209e+06

假设半径为 5742340.81

我发现this 资源似乎可以计算出正确的答案。但我无法解析它有何不同。

【问题讨论】:

  • 你如何定义 PI?使用您的代码以及 180 和 90 的输入,我得到 9.94552e-108.1209e+06 的输出。我使用#include &lt;math.h&gt; 定义了 PI
  • @J'e 不是你,而是 math.h 定义了M_PI,但这是非标准的。标准方式是std::numbers::pi in C++20
  • 对不起,我将 PI 定义为 3.14159

标签: c++ geo


【解决方案1】:

在你的solveNR()函数中你为什么使用

double nextTheta = theta - (2 * theta * std::sin(2 * theta) - PI * 
std::sin(latitude)) / (2 + 2 * std::cos(2 * theta));

改为

double nextTheta = theta - (2 * theta + std::sin(2 * theta) - PI * 
std::sin(latitude)) / (2 + 2 * std::cos(2 * theta));

似乎您应该使用“+”而不是“*”(在分子中的 2 * theta 之后),以符合 wiki-instructions。

【讨论】:

  • 这绝对有帮助!我仍然没有确切的正确答案,但谢谢!
猜你喜欢
  • 1970-01-01
  • 2020-09-11
  • 2015-05-06
  • 1970-01-01
  • 2011-02-08
  • 1970-01-01
  • 2013-05-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多