已知地面上矩形abcd区域,ab中点经纬度坐标中点o1 ,cd中点经纬度坐标o2,ab长度是6米,求abcd四个顶点坐标,c++编程
时间: 2023-09-30 14:04:08 浏览: 92
这道题需要知道一些地理计算的知识,包括经纬度和平面坐标的转换、地球半径等等。下面是一个可能的解法,仅供参考。
```
#include <iostream>
#include <cmath>
using namespace std;
const double R = 6371000; // 地球半径,单位是米
// 经纬度转平面坐标
void ll2xy(double lat, double lon, double& x, double& y) {
x = R * cos(lat) * lon;
y = R * lat;
}
// 平面坐标转经纬度
void xy2ll(double x, double y, double& lat, double& lon) {
lat = y / R;
lon = x / (R * cos(lat));
}
// 计算两点距离
double distance(double lat1, double lon1, double lat2, double lon2) {
double x1, y1, x2, y2;
ll2xy(lat1, lon1, x1, y1);
ll2xy(lat2, lon2, x2, y2);
double dx = x2 - x1;
double dy = y2 - y1;
return sqrt(dx * dx + dy * dy);
}
int main() {
double lat1 = 31.2314; // ab中点纬度
double lon1 = 121.4701; // ab中点经度
double lat2 = 31.2316; // cd中点纬度
double lon2 = 121.4705; // cd中点经度
double len = 6; // ab长度,单位是米
double dist = distance(lat1, lon1, lat2, lon2); // 计算cd和ab中点的距离
double angle = atan2(lon2 - lon1, lat2 - lat1); // 计算cd和ab中点之间的方位角
double lat3 = lat1 + len / (2 * R); // 计算ac线段中点的纬度
double lon3 = lon1 + len / (2 * R * cos(lat3)); // 计算ac线段中点的经度
double lat4 = lat3 + dist / (2 * R) * cos(angle + M_PI / 2); // 计算ad线段中点的纬度
double lon4 = lon3 + dist / (2 * R) * sin(angle + M_PI / 2) / cos(lat4); // 计算ad线段中点的经度
double x1, y1, x2, y2, x3, y3, x4, y4;
ll2xy(lat1, lon1, x1, y1);
ll2xy(lat2, lon2, x2, y2);
ll2xy(lat3, lon3, x3, y3);
ll2xy(lat4, lon4, x4, y4);
double dx = x3 - x1;
double dy = y3 - y1;
double ux = dx / len;
double uy = dy / len;
double vx = -uy;
double vy = ux;
double ax = x3 - ux * len / 2;
double ay = y3 - uy * len / 2;
double bx = x3 + ux * len / 2;
double by = y3 + uy * len / 2;
double cx = ax + vx * dist / 2;
double cy = ay + vy * dist / 2;
double dx = bx + vx * dist / 2;
double dy = by + vy * dist / 2;
double lat_a, lon_a, lat_b, lon_b, lat_c, lon_c, lat_d, lon_d;
xy2ll(ax, ay, lat_a, lon_a);
xy2ll(bx, by, lat_b, lon_b);
xy2ll(cx, cy, lat_c, lon_c);
xy2ll(dx, dy, lat_d, lon_d);
cout << "(" << lat_a << ", " << lon_a << ")" << endl;
cout << "(" << lat_b << ", " << lon_b << ")" << endl;
cout << "(" << lat_c << ", " << lon_c << ")" << endl;
cout << "(" << lat_d << ", " << lon_d << ")" << endl;
return 0;
}
```
这个程序中用到了经纬度和平面坐标的转换、计算两点距离、计算方位角等等地理计算的知识。最终输出的是abcd四个顶点的纬度和经度。注意这里的坐标系是平面坐标系,与实际地球表面的形状不完全一致,但可以近似地表示一个小区域的形状。
阅读全文