555555555555555

 

C++文件:zhuanhuan.cpp

#include <iostream>  

#include <cmath>  

constexpr auto PI = 3.14;

struct Point { double x, y, z; };

struct Coordinate { double lat, lon, height; };

Coordinate toGeodetic(const Point& point)

{

    const double a = 6378137.0;

    const double f = 1.0 / 298.257223563;

    const double b = a * (1 - f);

    const double e2 = (a * a - b * b) / (a * a);

    const double p = point.x / (a * a);

    const double q = point.y / (b * b);

    const double r = point.z / (b * b);

    Coordinate coord; coord.height = point.z;

    coord.lat = atan((e2 * q + r) / (p + q + r)) * 180 / PI; coord.lon = atan((q + r) / p) * 180 / PI;

    return coord;

}

Point toCartesian(const Coordinate& coord)

{

    const double a = 6378137.0;

    const double f = 1.0 / 298.257223563;

    const double b = a * (1 - f);

    const double e2 = (a * a - b * b) / (a * a);

    Point point;

    point.x = a * a * tan(coord.lat * PI / 180) * cos(coord.lon * PI / 180);

    point.y = b * b * tan(coord.lat * PI / 180) * sin(coord.lon * PI / 180);

    point.z = b * b * tan(coord.lat * PI / 180) * cos(coord.lon * PI / 180);

    return point;

}

void convertToGeodetic(Point point, Coordinate& coord)

{

    coord = toGeodetic(point);

}

void convertToCartesian(Coordinate coord, Point& point)

{

    point = toCartesian(coord);

}

int main() {

    Point AA = { -106935.2425, 5549269.5458, 3139220.0513 };

    Coordinate AAA = { 0,0,0 };

    convertToGeodetic(AA, AAA);

    std::cout << "AAAA: " << AAA.lat << ", " << AAA.lon << ", " << AAA.height << std::endl;

    Point BB = { -2661732.9209, 3581364.9183, 4542367.5601 };

    Coordinate BBB = { 0,0,0 };

    convertToGeodetic(BB, BBB);

    std::cout << "BBBB: " << BBB.lat << ", " << BBB.lon << ", " << BBB.height << std::endl;

    Point CC = { -2831733.2789,4675665.0430,3275373.1174 };

    Coordinate CCC = { 0,0,0 };

    convertToGeodetic(CC, CCC);

    std::cout << "CCCC: " << CCC.lat << ", " << CCC.lon << ", " << CCC.height << std::endl;

    Coordinate DD = { 30.531678420,114.357237473,28.1000 };

    Point DDD = { 0,0,0 };

    convertToCartesian(DD, DDD);

    std::cout << "DDDD: " << DDD.x << ", " << DDD.y << ", " << DDD.z << std::endl;

    Coordinate EE = { 43.808018931,87.600677706,852.9000 };

    Point EEE = { 0,0,0 };

    convertToCartesian(EE, EEE);

    std::cout << "EEEE: " << EEE.x << ", " << EEE.y << ", " << EEE.z << std::endl;

    Coordinate FF = { 31.099675186,121.200447167,23.2000 };

    Point FFF = { 0,0,0 };

    convertToCartesian(FF, FFF);

    std::cout << "FFFF: " << FFF.x << ", " << FFF.y << ", " << FFF.z << std::endl;

}  

输入命令行:g++ -std=c++11 zhuanhuan.cpp -o zhuanhuan

然后输入命令:./zhuanhuan

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值