내 연락처 정보
우편메소피아@프로톤메일.com
2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
목차
1. 가져온 데이터는 사진 이름과 대상 지점의 3차원 데이터로 구성된 txt 파일이므로 txt 파일의 데이터를 얻으려면 문자열 분할 기능을 설정해야 합니다.
5. 인접한 사진 사이에서 대상의 방향 변경 각도를 계산합니다.
6. 인접한 사진 사이에서 대상의 이동 거리와 속도를 계산합니다.
이 기사의 모든 코드는 CSDN 사용자 CV-X.WANG에서 제공한 것입니다. 개인이나 그룹은 상업적 활동이나 교육 활동을 수행할 수 없습니다.
- //字符串分割
- vector<string> split(const string &s, char delimiter) {
- vector<string> tokens;
- string token;
- istringstream tokenStream(s);
- while (getline(tokenStream, token, delimiter)) {
- tokens.push_back(token);
- }
- return tokens;
- }
#define M_PI 3.14159265358979323846 // pi
본 논문에서는 표적의 이동 방향을 평면 방향으로 획득하기 위해 군사 분야에서 흔히 사용되는 360° 방향 방식을 채택하고 있다. 즉, 진북은 0° 방향이고 시계 방향은 0-360°입니다. 예를 들어 진동 방향은 우리 방향 시스템에서는 90° 방향입니다.
일부,
더블 lon1_rad = lon1 * M_PI / 180.0;
이중 lat1_rad = lat1 * M_PI / 180.0;
더블 lon2_rad = lon2 * M_PI / 180.0;
이중 lat2_rad = lat2 * M_PI / 180.0;
라디안 단위입니다.
- //方向函数
- double calculateDirectionAngle(double lon1, double lat1, double lon2, double lat2) {
- // Convert degrees to radians
- double lon1_rad = lon1 * M_PI / 180.0;
- double lat1_rad = lat1 * M_PI / 180.0;
- double lon2_rad = lon2 * M_PI / 180.0;
- double lat2_rad = lat2 * M_PI / 180.0;
-
- // Calculate delta longitude and convert to radians
- double delta_lon_rad = (lon2 - lon1) * M_PI / 180.0;
-
- // Calculate y and x components
- double y = sin(delta_lon_rad) * cos(lat2_rad);
- double x = cos(lat1_rad) * sin(lat2_rad) - sin(lat1_rad) * cos(lat2_rad) * cos(delta_lon_rad);
-
- // Calculate direction angle in radians
- double direction_rad = atan2(y, x);
-
- // Convert direction angle to degrees
- double direction_deg = direction_rad * 180.0 / M_PI;
-
- // Ensure direction angle is within [0, 360) degrees
- if (direction_deg < 0) {
- direction_deg += 360.0;
- }
-
- return direction_deg;
- }
-
- ifstream file("LBH.txt");
- if (!file.is_open()) {
- cerr << "Could not open the file!" << endl;
- return 1;
- }
-
- string line;
- // Skip the header line
- getline(file, line);
-
- vector<vector<string>> extractedData;
-
- // Read each line from the file
- while (getline(file, line)) {
- vector<string> columns = split(line, 't');
- if (columns.size() < 16) {
- cerr << "Invalid line format" << endl;
- continue;
- }
-
- // Extract the required columns: 0, 13, 14, 15
- vector<string> extractedColumns;
- extractedColumns.push_back(columns[0]); // Image Name
- extractedColumns.push_back(columns[13]); // Longitude
- extractedColumns.push_back(columns[14]); // Latitude
- extractedColumns.push_back(columns[15]); // Altitude
-
- extractedData.push_back(extractedColumns);
- }
-
- file.close();
- cout << "Direction angles between adjacent image centers:" << endl;
- for (size_t i = 1; i < extractedData.size(); ++i) {
- //三角函数计算用弧度制
- double lon1 = (stod(extractedData[i - 1][1]))* M_PI/180; // Longitude
- double lat1 = (stod(extractedData[i - 1][2]))* M_PI / 180; // Latitude
- double lon2 = (stod(extractedData[i][1]))* M_PI / 180; // Longitude
- double lat2 = (stod(extractedData[i][2]))* M_PI / 180; // Latitude
- //计算方向变化角也要用弧度制
- double direction_angle = calculateDirectionAngle(lon1, lat1, lon2, lat2);
- cout << "lon1=" << lon1 << endl << "lat1=" << lat1 << endl << "lon2=" << lon2 << endl << "lat2=" << lat2 << endl;
- // Output Direction
- cout << "Direction from " << extractedData[i - 1][0] << " to " << extractedData[i][0] << ": " << direction_angle << " degrees" << endl;
참고: 여기서 얻은 거리의 계산 공식은 다음과 같습니다.
이는 가장 간단한 설명일 뿐입니다. 실제 상황에서는 보다 정확한 거리를 얻으려면 좌표계, 측정 영역 위치 등 일련의 조건을 고려해야 합니다.
- double lon2_1 = lon2 - lon1;
- double lat2_1 = lat2 - lat1;
- double lon_ = lon2_1 / 2;//1/2的Δlon
- double lat_ = lat2_1 / 2; //1 / 2的Δlat
- double sin2lon_ = sin(lon_)*sin(lon_);//sin²(1/2Δlon)
- double sin2lat_ = sin(lat_)*sin(lat_); //sin²(1 / 2Δlat)
- double cos_lat1 = cos(lat1);
- double cos_lat2 = cos(lat2);
- double sqrtA = sqrt(sin2lat_+ cos_lat1* cos_lat2*sin2lon_);
- //cout << "Direction from " << extractedData[i - 1][0] << " to " << extractedData[i][0] << ": " << "sqrtA =" << sqrtA << endl;
- double asinA = asin(sqrtA);
- //长半轴 短半轴 单位是m
- int a_r = 6378137.0;
- int b_r = 6356752;
- double Earth_R = (2 * a_r + b_r) / 3;
- double Distance = 2 * Earth_R*asinA;
- cout << "Distance From " << extractedData[i - 1][0] << " to " << extractedData[i][0] << ": " << "=" << Distance <<" meter"<< endl;
- int time = 3;//拍照间隔 s
- double speed = Distance / time;
- cout << "Speed From " << extractedData[i - 1][0] << " to " << extractedData[i][0] << ": " << "=" << speed << " meter per second" << endl;
- }
- #include <iostream>
- #include <fstream>
- #include <sstream>
- #include <vector>
- #include <cmath>
-
- using namespace std;
- #define M_PI 3.14159265358979323846 // pi
- // Function to split a string by a delimiter
- vector<string> split(const string &s, char delimiter) {
- vector<string> tokens;
- string token;
- istringstream tokenStream(s);
- while (getline(tokenStream, token, delimiter)) {
- tokens.push_back(token);
- }
- return tokens;
- }
-
- // direction angle in degrees
- //原理是 在平面上以正北方向为0°方向,顺时针为0-360°
- double calculateDirectionAngle(double lon1, double lat1, double lon2, double lat2) {
- // Convert degrees to radians
- double lon1_rad = lon1 * M_PI / 180.0;
- double lat1_rad = lat1 * M_PI / 180.0;
- double lon2_rad = lon2 * M_PI / 180.0;
- double lat2_rad = lat2 * M_PI / 180.0;
-
- // Calculate delta longitude and convert to radians
- double delta_lon_rad = (lon2 - lon1) * M_PI / 180.0;
-
- // Calculate y and x components
- double y = sin(delta_lon_rad) * cos(lat2_rad);
- double x = cos(lat1_rad) * sin(lat2_rad) - sin(lat1_rad) * cos(lat2_rad) * cos(delta_lon_rad);
-
- // Calculate direction angle in radians
- double direction_rad = atan2(y, x);
-
- // Convert direction angle to degrees
- double direction_deg = direction_rad * 180.0 / M_PI;
-
- // Ensure direction angle is within [0, 360) degrees
- if (direction_deg < 0) {
- direction_deg += 360.0;
- }
-
- return direction_deg;
- }
-
- int main() {
- ifstream file("LBH.txt");
- if (!file.is_open()) {
- cerr << "Could not open the file!" << endl;
- return 1;
- }
-
- string line;
- // Skip the header line
- getline(file, line);
-
- vector<vector<string>> extractedData;
-
- // Read each line from the file
- while (getline(file, line)) {
- vector<string> columns = split(line, 't');
- if (columns.size() < 16) {
- cerr << "Invalid line format" << endl;
- continue;
- }
-
- // Extract the required columns: 0, 13, 14, 15
- vector<string> extractedColumns;
- extractedColumns.push_back(columns[0]); // Image Name
- extractedColumns.push_back(columns[13]); // Longitude
- extractedColumns.push_back(columns[14]); // Latitude
- extractedColumns.push_back(columns[15]); // Altitude
-
- extractedData.push_back(extractedColumns);
- }
-
- file.close();
-
- // Calculate direction angles between adjacent image centers
- cout << "Direction angles between adjacent image centers:" << endl;
- for (size_t i = 1; i < extractedData.size(); ++i) {
- //三角函数计算用弧度制
- double lon1 = (stod(extractedData[i - 1][1]))* M_PI/180; // Longitude
- double lat1 = (stod(extractedData[i - 1][2]))* M_PI / 180; // Latitude
- double lon2 = (stod(extractedData[i][1]))* M_PI / 180; // Longitude
- double lat2 = (stod(extractedData[i][2]))* M_PI / 180; // Latitude
- //计算方向变化角也要用弧度制
- double direction_angle = calculateDirectionAngle(lon1, lat1, lon2, lat2);
- cout << "lon1=" << lon1 << endl << "lat1=" << lat1 << endl << "lon2=" << lon2 << endl << "lat2=" << lat2 << endl;
- // Output Direction
- cout << "Direction from " << extractedData[i - 1][0] << " to " << extractedData[i][0] << ": " << direction_angle << " degrees" << endl;
-
- double lon2_1 = lon2 - lon1;
- double lat2_1 = lat2 - lat1;
- double lon_ = lon2_1 / 2;//1/2的Δlon
- double lat_ = lat2_1 / 2; //1 / 2的Δlat
- double sin2lon_ = sin(lon_)*sin(lon_);//sin²(1/2Δlon)
- double sin2lat_ = sin(lat_)*sin(lat_); //sin²(1 / 2Δlat)
- double cos_lat1 = cos(lat1);
- double cos_lat2 = cos(lat2);
- double sqrtA = sqrt(sin2lat_+ cos_lat1* cos_lat2*sin2lon_);
- //cout << "Direction from " << extractedData[i - 1][0] << " to " << extractedData[i][0] << ": " << "sqrtA =" << sqrtA << endl;
- double asinA = asin(sqrtA);
- //长半轴 短半轴 单位是m
- int a_r = 6378137.0;
- int b_r = 6356752;
- double Earth_R = (2 * a_r + b_r) / 3;
- double Distance = 2 * Earth_R*asinA;
- cout << "Distance From " << extractedData[i - 1][0] << " to " << extractedData[i][0] << ": " << "=" << Distance <<" meter"<< endl;
- int time = 3;//拍照间隔 s
- double speed = Distance / time;
- cout << "Speed From " << extractedData[i - 1][0] << " to " << extractedData[i][0] << ": " << "=" << speed << " meter per second" << endl;
- }
- //cin.get();
-
- return 0;
- }