欢迎来到 SiteSMO | 思默AI智能问答平台!
注册或点击登录代表您同意《SiteSMO网络服务安全协议》
提示信息
请打开微信扫码登录
返回列表

C++代码实现将经纬度转换为笛卡尔坐标系中的x、y、z坐标

举报
454阅读 | 0人回复 | 2023-04-06 10:50:20

本帖由 x_n ... 发布,如有侵权联系删除 IP属地:山东

include

include

define PI 3.14159265

using namespace std;

struct Point3D{

double x;
double y;
double z;

};

Point3D convertToCartesian(double latitude, double longitude, double altitude){

Point3D point;
double radius = 6378137.0+altitude; // 地球半径+高度
longitude = longitude * PI / 180.0;
latitude = latitude * PI / 180.0;

point.x = radius * cos(latitude) * cos(longitude);
point.y = radius * cos(latitude) * sin(longitude);
point.z = radius * sin(latitude);

return point;

}

int main() {

double latitude, longitude, altitude;

cout << "输入经度:";
cin >> longitude;
cout << "输入纬度:";
cin >> latitude;
cout << "输入高度(m):";
cin >> altitude;

Point3D point = convertToCartesian(latitude, longitude, altitude);

cout << "笛卡尔坐标系中的坐标为:" << endl;
cout << "X: " << point.x << endl;
cout << "Y: " << point.y << endl;
cout << "Z: " << point.z << endl;

return 0;

}

复制
0
0

注:避免重复,不要就相同的标题进行反复追问。

回答共0个
回复禁止带推广链接、违法词及灌水,违规将封禁账号!!
您需要登录后才可以回复 注册 / 登录
每个账号仅有一次回答机会!
取消
提示信息
请选择举报理由
我要回答