矩阵、坐标变换、相控阵天线拟合方向图代码
矩阵、坐标变换、相控阵天线拟合方向图 代码
文章目录
- 矩阵、坐标变换、相控阵天线拟合方向图 代码
- 矩阵
- Matrix.h
- Matrix.cpp
- 坐标变换
- CConvert.h
- CConvert.cpp
- 相控阵天线分段拟合方向图
- CAntennaPattern.h
- CAntennaPattern.cpp
- ShowGragh.py
- 四
- CDetectedPattern.h
- CDetectedPattern.cpp
- CRadar.h
- CRadar.cpp
- CJam.h
- CJam.cpp
- RadarParam.ini
- JamParam.ini
- in.txt
矩阵
Matrix.h
#pragma once
#include <vector>
using namespace std;#define PI 3.14159265358979323846struct Matrix {int m = 0, n = 0;vector<vector<double>> data;Matrix();Matrix(int, int);Matrix operator +(const Matrix B);Matrix operator *(const double k);Matrix operator *(const Matrix B);void operator =(const Matrix B);void operator =(const double B[3][3]);void operator =(const double B[3][1]);void operator =(const vector<vector<double> > vec);void rotx(double); //角度制输入void roty(double); //角度制输入void rotz(double); //角度制输入void disp_matrix();
};
Matrix.cpp
#include "Matrix.h"Matrix::Matrix() {data.resize(0);
}Matrix::Matrix(int mm, int nn) {m = mm; n = nn;data.resize(mm);for (int i = 0; i < mm; i++)data[i].resize(nn);for (int i = 0; i < mm; i++)for (int j = 0; j < nn; j++)data[i][j] = 0;
}Matrix Matrix::operator+(Matrix B) {Matrix tmp;tmp = *this;if (m != B.m || n != B.n) return tmp;else {for (int i = 0; i < m; i++)for (int j = 0; j < n; j++)tmp.data[i][j] += B.data[i][j];return tmp;}
}Matrix Matrix::operator *(const double k) {Matrix tmp(m, n);for (int i = 0; i < m; i++)for (int j = 0; j < n; j++)tmp.data[i][j] = k * data[i][j];return tmp;
}Matrix Matrix::operator *(const Matrix B) { //m*n n*k -> m*kMatrix ans(m, B.n);if (n != B.m) return ans;else {for (int i = 0; i < m; i++)for (int j = 0; j < B.n; j++)for (int k = 0; k < n; k++)ans.data[i][j] += data[i][k] * B.data[k][j];return ans;}
}void Matrix::operator =(const Matrix B) {m = B.m;n = B.n;data.resize(B.m);for (int i = 0; i < B.m; i++)data[i].resize(B.n);data = B.data;
}void Matrix::operator =(const double B[3][3]) {int B_m = 3;int B_n = 3;m = B_m;n = B_n;data.resize(B_m);for (int i = 0; i < B_m; i++)data[i].resize(B_n);for (int i = 0; i < m; i++)for (int j = 0; j < n; j++)data[i][j] = B[i][j];
}void Matrix::operator =(const double B[3][1]) {int B_m = 3;int B_n = 1;m = B_m;n = B_n;data.resize(B_m);for (int i = 0; i < B_m; i++)data[i].resize(B_n);for (int i = 0; i < m; i++)for (int j = 0; j < n; j++)data[i][j] = B[i][j];
}void Matrix::operator =(const vector<vector<double> > vec) {data = vec;m = vec.size();n = vec[0].size();
}void Matrix::rotx(double phi) {phi = PI * phi / 180;double tmp[3][3] ={{1, 0, 0},{0, cos(phi), sin(phi)},{0, -sin(phi), cos(phi) }};*this = tmp;
}void Matrix::roty(double phi) {phi = PI * phi / 180;double tmp[3][3] ={{cos(phi), 0, -sin(phi)},{0, 1, 0},{sin(phi), 0, cos(phi)}};*this = tmp;
}void Matrix::rotz(double phi) {phi = PI * phi / 180;double tmp[3][3] ={{cos(phi), sin(phi), 0},{-sin(phi), cos(phi), 0},{0, 0, 1}};*this = tmp;
}void Matrix::disp_matrix() {for (int i = 0; i < m; i++) {for (int j = 0; j < n; j++)printf("%lf ", data[i][j]);putchar('\n');}
}
坐标变换
输入/输出 | 大地Cat | 地心Cat | 雷达Cat | 雷达Sph | 阵面Cat | 阵面Sph |
---|---|---|---|---|---|---|
大地Cat | (3)/ | (3)a | (6)ac | (6)ace | (8)aci | (8)acig |
地心Cat | (3)b | (3)/ | (6)c | (6)ce | (8)ci | (8)cig |
雷达Cat | (6)db | (6)d | (3)/ | (3)e | (5)i | (5)ig |
雷达Sph | (6)fdb | (6)fd | (3)f | (3)/ | (5)fi | (5)fig |
阵面Cat | (8)jdb | (8)jd | (5)j | (5)je | (3)/ | (3)g |
阵面Sph | (8)hjdb | (8)hjd | (5)hj | (5)hje | (3)h | (3)/ |
Cat 表示直角坐标系(笛卡尔系) Sph表示球坐标系
/ 表示自己变换为自己,不需要特别的函数
字母 a-j 分别对应手册上 a-j 的坐标变换方程
(x) 表示需要传入 x 个参数
(3)表示输入为需要变换的三坐标
(5)表示输入除了需要变换的三坐标,还需要 方位角、俯仰角
(6)表示输入除了需要变换的三坐标,还需要 经度、纬度、高程
(8)表示输入除了需要变换的三坐标,还需要 经度、纬度、高程、方位角、俯仰角
转换路径:如 hjdb 表示需要将输入坐标依次按照 h -> j -> d -> b 的顺序进行变换
CConvert.h
#pragma once
#include <vector>
#include "Matrix.h"
using namespace std;struct Coordinate {double d_c1 = 0;double d_c2 = 0;double d_c3 = 0;
};/*****basic functions*****/
Coordinate a_1to2(double, double, double);
Coordinate b_2to1(double, double, double);
Coordinate c_2to3(double, double, double, double, double, double);
Coordinate d_3to2(double, double, double, double, double, double);
Coordinate e_3to4(double, double, double);
Coordinate f_4to3(double, double, double);
Coordinate g_5to6(double, double, double);
Coordinate h_6to5(double, double, double);
Coordinate i_3to5(double, double, double, double, double);
Coordinate j_5to3(double, double, double, double, double);
/*****basic functions*****/
/*****self convert functions*****/
void self_1to1(double, double, double);
void self_2to2(double, double, double);
void self_3to3(double, double, double);
void self_4to4(double, double, double);
void self_5to5(double, double, double);
void self_6to6(double, double, double);
/*****self convert functions*****/
/*****indirect convert functions*****/ //含 cd,额外添加经纬度和高程;含 ij,额外添加方位角和俯仰角(double)
Coordinate ac_1to3(double, double, double, double, double, double);
Coordinate ace_1to4(double, double, double, double, double, double);
Coordinate aci_1to5(double, double, double, double, double, double, double, double);
Coordinate acig_1to6(double, double, double, double, double, double, double, double);
Coordinate ce_2to4(double, double, double, double, double, double);
Coordinate ci_2to5(double, double, double, double, double, double, double, double);
Coordinate cig_2to6(double, double, double, double, double, double, double, double);
Coordinate db_3to1(double, double, double, double, double, double);
Coordinate ig_3to6(double, double, double, double, double);
Coordinate fdb_4to1(double, double, double, double, double, double);
Coordinate fd_4to2(double, double, double, double, double, double);
Coordinate fi_4to5(double, double, double, double, double);
Coordinate fig_4to6(double, double, double, double, double);
Coordinate jdb_5to1(double, double, double, double, double, double, double, double);
Coordinate jd_5to2(double, double, double, double, double, double, double, double);
Coordinate je_5to4(double, double, double, double, double);
Coordinate hjdb_6to1(double, double, double, double, double, double, double, double);
Coordinate hjd_6to2(double, double, double, double, double, double, double, double);
Coordinate hj_6to3(double, double, double, double, double);
Coordinate hje_6to4(double, double, double, double, double);
/*****indirect convert functions*****/
/****************convert fuctions***************/
CConvert.cpp
#include "CConvert.h"
#include <cmath>#define PI 3.14159265358979323846/*** Self Functions ***/
void self_1to1(double input1, double input2, double input3) {Coordinate ans;ans.d_c1 = input1;ans.d_c2 = input2;ans.d_c3 = input3;return;
}
void self_2to2(double input1, double input2, double input3) {Coordinate ans;ans.d_c1 = input1;ans.d_c2 = input2;ans.d_c3 = input3;return;
}
void self_3to3(double input1, double input2, double input3) {Coordinate ans;ans.d_c1 = input1;ans.d_c2 = input2;ans.d_c3 = input3;return;
}
void self_4to4(double input1, double input2, double input3) {Coordinate ans;ans.d_c1 = input1;ans.d_c2 = input2;ans.d_c3 = input3;return;
}
void self_5to5(double input1, double input2, double input3) {Coordinate ans;ans.d_c1 = input1;ans.d_c2 = input2;ans.d_c3 = input3;return;
}
void self_6to6(double input1, double input2, double input3) {Coordinate ans;ans.d_c1 = input1;ans.d_c2 = input2;ans.d_c3 = input3;return;
}
/*** Self Functions ***//*****basic functions*****/
Coordinate a_1to2(double Input1, double Input2, double Input3) {Coordinate ans;/***** basic variables *****/double L = PI * Input1 / 180, B = PI * Input2 / 180, H = Input3;double a = 6378140, b = 6356755, e2 = 0.00669;double N = a / (sqrt(1 - e2 * sin(B) * sin(B)));/***** basic variables *****//***** Convert Function *****/ans.d_c1 = (N + H) * cos(B) * cos(L);ans.d_c2 = (N + H) * cos(B) * sin(L);ans.d_c3 = (N * (1 - e2) + H) * sin(B);/***** Convert Function *****/return ans;
}
Coordinate b_2to1(double Input1, double Input2, double Input3) {Coordinate ans;/***** basic variables *****/double x0 = Input1, y0 = Input2, z0 = Input3;double a = 6378140, b = 6356755, e = 0.00669;/***** basic variables *****//***** Convert Function *****/if (x0 > 0) {ans.d_c1 = 180 * atan(y0 / x0) / PI;}else if (x0 < 0) {ans.d_c1 = 180 * (PI + atan(y0 / x0)) / PI;}else if (abs(x0) <= 0.0001 && y0 > 0) {ans.d_c1 = 180;}else if (abs(x0) <= 0.0001 && y0 < 0) {ans.d_c1 = -180;}else ans.d_c1 = 0;double tmp0 = pow(1 - e * e, -1);ans.d_c2 = 180 * atan(z0 / (sqrt(x0 * x0 + y0 * y0)) * tmp0) / PI;double tmp1 = a * a * z0 * z0 / (x0 * x0 + y0 * y0 + z0 * z0), tmp2 = b * b * (1 - (z0 * z0) / (x0 * x0 + y0 * y0 + z0 * z0));ans.d_c3 = sqrt(x0 * x0 + y0 * y0 + z0 * z0) - a * b / sqrt(tmp1 + tmp2);/***** Convert Function *****/return ans;
}
Coordinate c_2to3(double Input1, double Input2, double Input3, double lambda_r, double phi_r, double HR) {Coordinate ans;/***** basic variables *****/Coordinate Cod_r = a_1to2(lambda_r, phi_r, HR);Matrix A(3, 3), B(3, 3), C(3, 3), D(3, 1), res(0, 0);double x0 = Input1, y0 = Input2, z0 = Input3;double xr0 = Cod_r.d_c1, yr0 = Cod_r.d_c2, zr0 = Cod_r.d_c3;double X = x0 - xr0, Y = y0 - yr0, Z = z0 - zr0;D.data[0][0] = X; D.data[1][0] = Y; D.data[2][0] = Z;A.roty(-90); B.rotx(phi_r); C.rotz(lambda_r - 90);/***** basic variables *****//***** Convert Function *****/res = A * B * C * D;ans.d_c1 = res.data[0][0];ans.d_c2 = res.data[1][0];ans.d_c3 = res.data[2][0];/***** Convert Function *****/return ans;
}
Coordinate d_3to2(double Input1, double Input2, double Input3, double lambda_r, double phi_r, double HR) {Coordinate ans;/***** basic variables *****/Coordinate Cod_r = a_1to2(lambda_r, phi_r, HR);Matrix A(3, 3), B(3, 3), C(3, 3), D(3, 1), res(0, 0);double x0 = Input1, y0 = Input2, z0 = Input3;double xr0 = Cod_r.d_c1, yr0 = Cod_r.d_c2, zr0 = Cod_r.d_c3;D.data[0][0] = x0; D.data[1][0] = y0; D.data[2][0] = z0;A.rotz(90 - lambda_r); B.rotx(-phi_r); C.roty(90);/***** basic variables *****//***** Convert Function *****/res = A * B * C * D;ans.d_c1 = res.data[0][0] + xr0;ans.d_c2 = res.data[1][0] + yr0;ans.d_c3 = res.data[2][0] + zr0;/***** Convert Function *****/return ans;
}
Coordinate e_3to4(double Input1, double Input2, double Input3) {Coordinate ans;/***** basic variables *****/double x = Input1, y = Input2, z = Input3;/***** basic variables *****//***** Convert Function *****/ans.d_c1 = sqrt(x * x + y * y + z * z);if (z > 0) {ans.d_c2 = 180 * acos(x / (sqrt(x * x + z * z))) / PI;}else if (z < 0) {ans.d_c2 = 360 - 180 * acos(x / (sqrt(x * x + z * z))) / PI;}else z = 0;ans.d_c3 = 180 * asin(y / ans.d_c1) / PI;/***** Convert Function *****/return ans;
}
Coordinate f_4to3(double Input1, double Input2, double Input3) {Coordinate ans;/***** basic variables *****/double r = Input1, theta = PI * Input2 / 180.0, phi = PI * Input3 / 180.0;/***** basic variables *****//***** Convert Function *****/ans.d_c1 = r * cos(phi) * cos(theta);ans.d_c2 = r * sin(phi);ans.d_c3 = r * cos(phi) * sin(theta);/***** Convert Function *****/return ans;
}
Coordinate g_5to6(double Input1, double Input2, double Input3) {Coordinate ans;/***** basic variables *****/double x = Input1, y = Input2, z = Input3;/***** basic variables *****//***** Convert Function *****/ans.d_c1 = sqrt(x * x + y * y + z * z);if (y > 0) {ans.d_c2 = 180 * acos(x / sqrt(x * x + y * y)) / PI;}else if (y < 0) {ans.d_c2 = 360 - 180 * acos(x / sqrt(x * x + y * y)) / PI;}else ans.d_c2 = 0;ans.d_c3 = 180 * acos(z / ans.d_c1) / PI;/***** Convert Function *****/return ans;
}
Coordinate h_6to5(double Input1, double Input2, double Input3) {Coordinate ans;/***** basic variables *****/double r = Input1, theta = PI * Input2 / 180, phi = PI * Input3 / 180;/***** basic variables *****//***** Convert Function *****/ans.d_c1 = r * sin(phi) * cos(theta);ans.d_c2 = r * sin(phi) * sin(theta);ans.d_c3 = r * cos(phi);/***** Convert Function *****/return ans;
}
Coordinate i_3to5(double Input1, double Input2, double Input3, double Ap, double Ep) {Coordinate ans;/***** basic variables *****/double x = Input1, y = Input2, z = Input3;/***** basic variables *****//***** Convert Function *****/Matrix A(3, 3), B(3, 3), C(3, 1), res(0, 0);A.rotx(-Ep); B.roty(-Ap);double t[3][1] = { {x},{y},{z} };C = t;res = A * B * C;ans.d_c1 = res.data[0][0];ans.d_c2 = res.data[1][0];ans.d_c3 = res.data[2][0];/***** Convert Function *****/return ans;
}
Coordinate j_5to3(double Input1, double Input2, double Input3, double Ap, double Ep) {Coordinate ans;/***** basic variables *****/double x = Input1, y = Input2, z = Input3;/***** basic variables *****//***** Convert Function *****/Matrix A(3, 3), B(3, 3), C(3, 1), res(0, 0);A.roty(Ap); B.rotx(Ep);double t[3][1] = { {x},{y},{z} };C = t;res = A * B * C;ans.d_c1 = res.data[0][0];ans.d_c2 = res.data[1][0];ans.d_c3 = res.data[2][0];/***** Convert Function *****/return ans;
}
/*****basic functions*****//*****indirect convert functions*****/ //含 cd,额外添加经纬度和高程;含 ij,额外添加方位角和俯仰角(double)
Coordinate ig_3to6(double Input1, double Input2, double Input3, double Ap, double Ep) {Coordinate ans;/***** basic variables *****//***** basic variables *****//***** Convert Function *****/ans = i_3to5(Input1, Input2, Input3, Ap, Ep);ans = g_5to6(ans.d_c1, ans.d_c2, ans.d_c3);/***** Convert Function *****/return ans;
}
Coordinate fi_4to5(double Input1, double Input2, double Input3, double Ap, double Ep) {Coordinate ans;/***** basic variables *****//***** basic variables *****//***** Convert Function *****/ans = f_4to3(Input1, Input2, Input3);ans = i_3to5(ans.d_c1, ans.d_c2, ans.d_c3, Ap, Ep);/***** Convert Function *****/return ans;
}
Coordinate fig_4to6(double Input1, double Input2, double Input3, double Ap, double Ep) {Coordinate ans;/***** basic variables *****//***** basic variables *****//***** Convert Function *****/ans = f_4to3(Input1, Input2, Input3);ans = i_3to5(ans.d_c1, ans.d_c2, ans.d_c3, Ap, Ep);ans = g_5to6(ans.d_c1, ans.d_c2, ans.d_c3);/***** Convert Function *****/return ans;
}
Coordinate je_5to4(double Input1, double Input2, double Input3, double Ap, double Ep) {Coordinate ans;/***** basic variables *****//***** basic variables *****//***** Convert Function *****/ans = j_5to3(Input1, Input2, Input3, Ap, Ep);ans = e_3to4(ans.d_c1, ans.d_c2, ans.d_c3);/***** Convert Function *****/return ans;
}
Coordinate hj_6to3(double Input1, double Input2, double Input3, double Ap, double Ep) {Coordinate ans;/***** basic variables *****//***** basic variables *****//***** Convert Function *****/ans = h_6to5(Input1, Input2, Input3);ans = j_5to3(ans.d_c1, ans.d_c2, ans.d_c3, Ap, Ep);/***** Convert Function *****/return ans;
}
Coordinate hje_6to4(double Input1, double Input2, double Input3, double Ap, double Ep) {Coordinate ans;/***** basic variables *****//***** basic variables *****//***** Convert Function *****/ans = h_6to5(Input1, Input2, Input3);ans = j_5to3(ans.d_c1, ans.d_c2, ans.d_c3, Ap, Ep);ans = e_3to4(ans.d_c1, ans.d_c2, ans.d_c3);/***** Convert Function *****/return ans;
}Coordinate ac_1to3(double Input1, double Input2, double Input3, double lambda_r, double phi_r, double HR) {Coordinate ans;/***** basic variables *****//***** basic variables *****//***** Convert Function *****/ans = a_1to2(Input1, Input2, Input3);ans = c_2to3(ans.d_c1, ans.d_c2, ans.d_c3, lambda_r, phi_r, HR);/***** Convert Function *****/return ans;
}
Coordinate ace_1to4(double Input1, double Input2, double Input3, double lambda_r, double phi_r, double HR) {Coordinate ans;/***** basic variables *****//***** basic variables *****//***** Convert Function *****/ans = a_1to2(Input1, Input2, Input3);ans = c_2to3(ans.d_c1, ans.d_c2, ans.d_c3, lambda_r, phi_r, HR);ans = e_3to4(ans.d_c1, ans.d_c2, ans.d_c3);/***** Convert Function *****/return ans;
}
Coordinate ce_2to4(double Input1, double Input2, double Input3, double lambda_r, double phi_r, double HR) {Coordinate ans;/***** basic variables *****//***** basic variables *****//***** Convert Function *****/ans = c_2to3(Input1, Input2, Input3, lambda_r, phi_r, HR);ans = e_3to4(ans.d_c1, ans.d_c2, ans.d_c3);/***** Convert Function *****/return ans;
}
Coordinate db_3to1(double Input1, double Input2, double Input3, double lambda_r, double phi_r, double HR) {Coordinate ans;/***** basic variables *****//***** basic variables *****//***** Convert Function *****/ans = d_3to2(Input1, Input2, Input3, lambda_r, phi_r, HR);ans = b_2to1(ans.d_c1, ans.d_c2, ans.d_c3);/***** Convert Function *****/return ans;
}
Coordinate fdb_4to1(double Input1, double Input2, double Input3, double lambda_r, double phi_r, double HR) {Coordinate ans;/***** basic variables *****//***** basic variables *****//***** Convert Function *****/ans = f_4to3(Input1, Input2, Input3);ans = d_3to2(ans.d_c1, ans.d_c2, ans.d_c3, lambda_r, phi_r, HR);ans = b_2to1(ans.d_c1, ans.d_c2, ans.d_c3);/***** Convert Function *****/return ans;
}
Coordinate fd_4to2(double Input1, double Input2, double Input3, double lambda_r, double phi_r, double HR) {Coordinate ans;/***** basic variables *****//***** basic variables *****//***** Convert Function *****/ans = f_4to3(Input1, Input2, Input3);ans = d_3to2(ans.d_c1, ans.d_c2, ans.d_c3, lambda_r, phi_r, HR);/***** Convert Function *****/return ans;
}Coordinate aci_1to5(double Input1, double Input2, double Input3, double lambda_r, double phi_r, double HR, double Ap, double Ep) {Coordinate ans;/***** basic variables *****//***** basic variables *****//***** Convert Function *****/ans = a_1to2(Input1, Input2, Input3);ans = c_2to3(ans.d_c1, ans.d_c2, ans.d_c3, lambda_r, phi_r, HR);ans = i_3to5(ans.d_c1, ans.d_c2, ans.d_c3, Ap, Ep);/***** Convert Function *****/return ans;
}
Coordinate acig_1to6(double Input1, double Input2, double Input3, double lambda_r, double phi_r, double HR, double Ap, double Ep) {Coordinate ans;/***** basic variables *****//***** basic variables *****//***** Convert Function *****/ans = a_1to2(Input1, Input2, Input3);ans = c_2to3(ans.d_c1, ans.d_c2, ans.d_c3, lambda_r, phi_r, HR);ans = i_3to5(ans.d_c1, ans.d_c2, ans.d_c3, Ap, Ep);ans = g_5to6(ans.d_c1, ans.d_c2, ans.d_c3);/***** Convert Function *****/return ans;
}
Coordinate ci_2to5(double Input1, double Input2, double Input3, double lambda_r, double phi_r, double HR, double Ap, double Ep) {Coordinate ans;/***** basic variables *****//***** basic variables *****//***** Convert Function *****/ans = c_2to3(Input1, Input2, Input3, lambda_r, phi_r, HR);ans = i_3to5(ans.d_c1, ans.d_c2, ans.d_c3, Ap, Ep);/***** Convert Function *****/return ans;
}
Coordinate cig_2to6(double Input1, double Input2, double Input3, double lambda_r, double phi_r, double HR, double Ap, double Ep) {Coordinate ans;/***** basic variables *****//***** basic variables *****//***** Convert Function *****/ans = c_2to3(Input1, Input2, Input3, lambda_r, phi_r, HR);ans = i_3to5(ans.d_c1, ans.d_c2, ans.d_c3, Ap, Ep);ans = g_5to6(ans.d_c1, ans.d_c2, ans.d_c3);/***** Convert Function *****/return ans;
}
Coordinate jdb_5to1(double Input1, double Input2, double Input3, double lambda_r, double phi_r, double HR, double Ap, double Ep) {Coordinate ans;/***** basic variables *****//***** basic variables *****//***** Convert Function *****/ans = j_5to3(Input1, Input2, Input3, Ap, Ep);ans = d_3to2(ans.d_c1, ans.d_c2, ans.d_c3, lambda_r, phi_r, HR);ans = b_2to1(ans.d_c1, ans.d_c2, ans.d_c3);/***** Convert Function *****/return ans;
}
Coordinate jd_5to2(double Input1, double Input2, double Input3, double lambda_r, double phi_r, double HR, double Ap, double Ep) {Coordinate ans;/***** basic variables *****//***** basic variables *****//***** Convert Function *****/ans = j_5to3(Input1, Input2, Input3, Ap, Ep);ans = d_3to2(ans.d_c1, ans.d_c2, ans.d_c3, lambda_r, phi_r, HR);/***** Convert Function *****/return ans;
}
Coordinate hjdb_6to1(double Input1, double Input2, double Input3, double lambda_r, double phi_r, double HR, double Ap, double Ep) {Coordinate ans;/***** basic variables *****//***** basic variables *****//***** Convert Function *****/ans = h_6to5(Input1, Input2, Input3);ans = j_5to3(ans.d_c1, ans.d_c2, ans.d_c3, Ap, Ep);ans = d_3to2(ans.d_c1, ans.d_c2, ans.d_c3, lambda_r, phi_r, HR);ans = b_2to1(ans.d_c1, ans.d_c2, ans.d_c3);/***** Convert Function *****/return ans;
}
Coordinate hjd_6to2(double Input1, double Input2, double Input3, double lambda_r, double phi_r, double HR, double Ap, double Ep) {Coordinate ans;/***** basic variables *****//***** basic variables *****//***** Convert Function *****/ans = h_6to5(Input1, Input2, Input3);ans = j_5to3(ans.d_c1, ans.d_c2, ans.d_c3, Ap, Ep);ans = d_3to2(ans.d_c1, ans.d_c2, ans.d_c3, lambda_r, phi_r, HR);/***** Convert Function *****/return ans;
}/*****indirect convert functions*****/
相控阵天线分段拟合方向图
CAntennaPattern.h
#pragma once
#pragma warning(disable:4996)
#include <Windows.h>
#include <iostream>
#include <cmath>#define PI 3.14159265358979323846class CAntennaPattern
{
private:double m_G0_dB;double m_thetab;double m_alpha1;double m_alpha2;double m_alpha3;double m_A1_dB;double m_angle_floor;double m_angle_ceil;double m_angle_step;public:void Get_Param();double AntennaPatternModel_SelfParam(double Delta);void Antenna_PrintDataToFile_SelfParam();
};inline double angle_to_rad(double angle); //turn angle to radiant
inline double dB_to_Gain(double dB);
double Sa(double rad); //radiant system input//Antenna Pattern Model, Input Antenna Parameters and differencial angle, Output Amplitude Gain
double AntennaPatternModel_Function_F(double thetab, double alpha1, double alpha2, double alpha3, \double A1_dB, double Delta);//Antenna Pattern Model, Input Antenna Parameters and differencial angle, Output Antenna Gain_dB
double AntennaPatternModel(double G0, \double thetab, double alpha1, double alpha2, double alpha3, \double A1_dB, double Delta);double Cal_Delta(double thetat, double phit, double thetar, double phir);//阵面直角坐标系的应用
CAntennaPattern.cpp
#include "CAntennaPattern.h"inline double angle_to_rad(double angle) {return PI * angle / 180;
}inline double dB_to_Gain(double dB) {return pow(10, dB / 20.0);
}double Sa(double rad) {if (abs(rad) <= 1e-10) return 1;else return sin(rad) / rad;
}double AntennaPatternModel_Function_F(double thetab, double alpha1, double alpha2, double alpha3, \double A1_dB, double Delta) {Delta = abs(Delta);double tmp_A1 = dB_to_Gain(A1_dB);/***** Function_F *****/if (abs(Delta - 2) <= 1e-10) return 0.000002338429523806; //人为定义 +-2 奇异点的值if (Delta < thetab / 2) return Sa(2.7834 * Delta / thetab);else if (Delta < alpha1)return Sa(1.3917 + (3.4998) / (2 * alpha1 - thetab) * (Delta - thetab / 2));else if (Delta < alpha2)return abs((tmp_A1 / 0.2172) * Sa(1.3518 / (alpha2 - alpha1)\* (Delta - alpha1) + PI));elsereturn abs((tmp_A1 / 0.2172) * Sa(1.7898 / (alpha3 - alpha2)\* (Delta - alpha2) + 4.4934));/***** Function_F *****/
}double AntennaPatternModel(double G0_dB, \double thetab, double alpha1, double alpha2, double alpha3, \double A1_dB, double Delta) {if (abs(Delta - 2) <= 1e-10) return -72.62; //人为定义 +-2 奇异点的值else {double F = abs(AntennaPatternModel_Function_F(thetab, alpha1,\alpha2, alpha3, A1_dB, Delta));return G0_dB + 20 * log10(F);}
}double Cal_Delta(double thetat, double phit, double thetar, double phir) {thetat = angle_to_rad(thetat);thetar = angle_to_rad(thetar);phit = angle_to_rad(phit);phir = angle_to_rad(phir);double Delta = acos(sin(thetar) * sin(thetat) * cos(phir - phit)\+ cos(thetar) * cos(thetat));while (Delta < 0) Delta += PI;while (Delta > PI) Delta -= PI;return 180 * Delta / PI;
}void CAntennaPattern::Get_Param() {freopen("in.txt", "r", stdin);std::cin >> m_G0_dB >> m_thetab >> m_alpha1 >> m_alpha2 \>> m_alpha3 >> m_A1_dB >> m_angle_floor >> m_angle_ceil >> m_angle_step;
}double CAntennaPattern::AntennaPatternModel_SelfParam(double Delta) {return AntennaPatternModel(m_G0_dB, m_thetab, \m_alpha1, m_alpha2, m_alpha3, m_A1_dB, Delta);
}void CAntennaPattern::Antenna_PrintDataToFile_SelfParam() {FILE* pFile = fopen("out.txt", "w");for (double i = m_angle_floor; i <= m_angle_ceil; i += m_angle_step) {fprintf(pFile, "%.18lf %lf\n", i, AntennaPatternModel_SelfParam(abs(i)));}fclose(pFile);system("python C:\\Users\\xxxxx\\Desktop\\Python_Project\\ShowGragh.py");
}
ShowGragh.py
import matplotlib.pyplot as plt
import numpy as npfile = open(r"C:\Users\xxxxx\Desktop\C++_Project\out.txt")
dat = file.readlines()tmp_x = []
tmp_y = []
for i in range(len(dat)):tmp=dat[i].split(' ')tmp_x.append(float(tmp[0]))tmp_y.append(float(tmp[1][0:-1]))
x = np.array(tmp_x)
y = np.array(tmp_y)plt.plot(x,y)
plt.show()
四
CDetectedPattern.h
#pragma once
#include "CJam.h"
#include "CRadar.h"
#include <cmath>
#include <Windows.h>#define PI 3.14159265358979323846class CDetectPattern
{
public:double m_RCS; // m*mdouble m_start; // m but take km as inputdouble m_end; // m but take km as inputdouble m_step; // m but take km as inputbool m_isJamed; // consider jam or notCRadar m_radar; CJam m_jam;public:CDetectPattern(double RCS, int start, int end, int step, bool isJamed);void Set_Range(int start, int end, int step); //set display rangevoid Set_isJamed(bool isJamed); //set it is jamed or notdouble Ps_Echo_Power(double R); //Calculate Ps which is Echo Wave Powerdouble Prj_Jam_Power(double R); //Calculate Prj which is Jam signal Powerdouble Pn_Receiver_Noise_AvgPower(); //Calculate Pn which is Receiver Noise Average Powerdouble Cal_SNR(double R); //Calculate SNR return (dB)double Cal_Pd(double R); //Calculate Pd ¼ì²â¸ÅÂÊ £» Pf Ð龯¸ÅÂÊvoid Print_SNR_to_File(); //print SNR result to outSNR.txtvoid Print_Pd_to_File(); //print Pd result to outPd.txt
};inline double dB_to_Gain_20log(double dB);
inline double Gain_to_dB_20log(double Gain);
inline double dB_to_Gain_10log(double dB);
inline double Gain_to_dB_10log(double Gain);double showPdFit(double x,int p);
CDetectedPattern.cpp
#include "pch.h"
#include "CDetectPattern.h"double FittingParam[3][13] =
{{-2.97653932377928e-11, 3.62018347014853e-09, -1.91340754314287e-07, 5.74551189234617e-06, -0.000107298352060326, 0.00127409114954349, -0.00923478177990487, 0.032817704051691, 0.039525045009544, -0.965588439831872, 4.27745426576399, -8.6470366058232, 6.88883923340686},{-7.30274553849313e-11, 1.06540825657799e-08, -6.90474119074791e-07, 2.62247829417352e-05, -0.000648591127757693, 0.010978807795127, -0.130144003844152, 1.08652678714639, -6.33045320808385, 25.0706731077309, -64.0035482290751, 94.5254653110359, -61.0756433489587},{ 1.69780417128538e-10, -2.26832918097651e-08, 1.34905924407883e-06, -4.71367079340838e-05, 0.00107563568762147, -0.0168583158625442, 0.185773997054586, -1.44813888121954, 7.91473911168946, -29.5455326351864, 71.4458835346225, -100.436187508087, 62.0670879041075}
};inline double dB_to_Gain_20log(double dB){return pow(10, dB / 20.0);
}inline double Gain_to_dB_20log(double Gain){return 20 * log10(Gain);
}inline double dB_to_Gain_10log(double dB) {return pow(10, dB / 10.0);
}inline double Gain_to_dB_10log(double Gain) {return 10 * log10(Gain);
}CDetectPattern::CDetectPattern(double RCS, int start, int end, int step, bool isJamed)
{m_RCS = RCS;m_start = 1000 * start; //ͳһΪ m m_end = 1000 * end;m_step = 1000 * step;m_isJamed = isJamed;m_radar.Get_Radar_Config();m_jam.Get_Jam_Config();
}void CDetectPattern::Set_Range(int start, int end, int step){m_start = 1000 * start; //ͳһΪ m m_end = 1000 * end;m_step = 1000 * step;
}void CDetectPattern::Set_isJamed(bool isJamed){m_isJamed = isJamed;
}double CDetectPattern::Ps_Echo_Power(double R)
{int Pt = m_radar.m_peakPower; double L = dB_to_Gain_10log(m_radar.m_generalLoss);double Gt = dB_to_Gain_10log(m_radar.m_maxGain);double Gr = Gt;double lambda = 3e8 / m_radar.m_carryFreq;double fenzi = Pt * Gt * Gr * lambda * lambda;double fenmu = pow(4 * PI, 3) * pow(R, 4) * L;return fenzi / fenmu;
}double CDetectPattern::Prj_Jam_Power(double R)
{int Bj = m_jam.m_jamBand;int Pj = m_jam.m_jamPower;int Br = m_radar.m_instantBand;double Gj = dB_to_Gain_10log(m_jam.m_maxGain);double Grj = dB_to_Gain_10log(m_radar.m_maxGain);double Lj = dB_to_Gain_10log(m_jam.m_transmitLoss);double Lr = dB_to_Gain_10log(m_jam.m_receiveLoss);double lambda = 3e8 / m_radar.m_carryFreq;double fenzi = Pj * Gj * Grj * lambda * lambda * Br;double fenmu = pow(4 * PI * R, 2) * Lj * Lr * Bj;return fenzi / fenmu;
}double CDetectPattern::Pn_Receiver_Noise_AvgPower()
{int T0 = 290;double k = 1.38e-23;double Bn = m_radar.m_instantBand;double NF = dB_to_Gain_10log(m_radar.m_noiseFig);return k * T0 * Bn * NF;
}double CDetectPattern::Cal_SNR(double R){ //return (dB)if(m_isJamed) return Gain_to_dB_10log( Ps_Echo_Power(R) / (Pn_Receiver_Noise_AvgPower() + Prj_Jam_Power(R)) );else return Gain_to_dB_10log( Ps_Echo_Power(R) / Pn_Receiver_Noise_AvgPower() );
}double CDetectPattern::Cal_Pd(double R)
{double Pf = m_radar.m_falseAlarmRate;double SNR = Cal_SNR(R);if (SNR <= 3) {if (abs(Pf - 1e-6) < 1e-10) return 1e-3;else if (abs(Pf - 1e-9) < 1e-10) return 1e-4;else if (abs(Pf - 1e-12) < 1e-10) return 1e-7;else return -1;}else if (SNR >= 20) {return 0.999999;}else {double ans = 0;if (abs(Pf - 1e-6) < 1e-10) {for (int i = 1; i <= 13; i++)ans += FittingParam[0][i - 1] * pow(SNR, 13 - i);if (ans > 1)ans = 0.999999;return ans;}else if (abs(Pf - 1e-9) < 1e-10) {for (int i = 1; i <= 13; i++)ans += FittingParam[1][i - 1] * pow(SNR, 13 - i);if (ans > 1)ans = 0.999999;return ans;}else if (abs(Pf - 1e-12) < 1e-10) {for (int i = 1; i <= 13; i++)ans += FittingParam[2][i - 1] * pow(SNR, 13 - i);if (ans > 1)ans = 0.999999;return ans;}else return -1;}
}void CDetectPattern::Print_SNR_to_File()
{FILE* pFile = fopen("outSNR.txt", "w");for (int R = m_start; R >= m_end; R += m_step) {fprintf(pFile, "%d %lf\n", R/1000, Cal_SNR(R));}fclose(pFile);system("python showSNR.py");
}void CDetectPattern::Print_Pd_to_File()
{FILE* pFile = fopen("outPd.txt", "w");for (int R = m_start; R >= m_end; R += m_step) {fprintf(pFile, "%d %lf\n", R/1000, Cal_Pd(R));}fclose(pFile);system("python showPd.py");
}double showPdFit(double x,int p)
{double ans = 0;for (int i = 1; i <= 13; i++)ans += FittingParam[p][i - 1] * pow(x, 13 - i);return ans;
}
CRadar.h
#pragma once
#pragma warning(disable:4996)
#include <iostream>class CRadar
{
public:double m_peakPower; //KW - Wdouble m_carryFreq; //MHz - Hzdouble m_maxGain; //dB - Lineardouble m_generalLoss; //dB - Lineardouble m_instantBand; //MHz - Hzdouble m_noiseFig; //dB - Lineardouble m_falseAlarmRate;void Get_Radar_Config(); //read & parse RadarParam.inivoid print_Radar_Param();
};
CRadar.cpp
#pragma warning(disable:6031)
#include "pch.h"
#include "CRadar.h"void CRadar::Get_Radar_Config()
{FILE* pFile;pFile = fopen("RadarParam.ini","r");fscanf(pFile, "[雷达参数]\n");fscanf(pFile, "峰值功率(kW)=%lf\n", &m_peakPower); m_peakPower *= 1000; //功率统一为 瓦fscanf(pFile, "载频(MHz)=%lf\n", &m_carryFreq); m_carryFreq *= 1000000;fscanf(pFile, "天线最大增益(dB)=%lf\n", &m_maxGain);fscanf(pFile, "雷达系统综合损耗(dB)=%lf\n", &m_generalLoss);fscanf(pFile, "接收机瞬时带宽(MHz)=%lf\n", &m_instantBand); m_instantBand *= 1000000;fscanf(pFile, "噪声系数(dB)=%lf\n", &m_noiseFig);fscanf(pFile, "虚警概率=%lf\n", &m_falseAlarmRate);fclose(pFile);
}void CRadar::print_Radar_Param() {printf("%d %d %d %d %d %d %.8lf\n", m_peakPower, m_carryFreq, m_maxGain, m_generalLoss,\m_instantBand, m_noiseFig, m_falseAlarmRate);
}
CJam.h
#pragma once
#pragma warning(disable:4996)
#include <iostream>class CJam
{
public:double m_jamPower; //Wdouble m_centerFreq; //MHz - Hzdouble m_jamBand; //MHz - Hzdouble m_maxGain; //dB - Lineardouble m_transmitLoss; //dB - Lineardouble m_receiveLoss; //dB - Linearvoid Get_Jam_Config();void print_Jam_Param();
};
CJam.cpp
#pragma warning(disable:6031)
#include "pch.h"
#include "CJam.h"void CJam::Get_Jam_Config()
{FILE* pFile;pFile = fopen("JamParam.ini", "r");fscanf(pFile, "[干扰参数]\n");fscanf(pFile, "干扰功率(W)=%lf\n", &m_jamPower);fscanf(pFile, "中心频率(MHz)=%lf\n", &m_centerFreq); m_centerFreq *= 100000;fscanf(pFile, "干扰带宽(MHz)=%lf\n", &m_jamBand); m_jamBand *= 1000000;fscanf(pFile, "天线最大增益(dB)=%lf\n", &m_maxGain);fscanf(pFile, "干扰机发射综合损耗(dB)=%lf\n", &m_transmitLoss);fscanf(pFile, "雷达接收综合损耗(dB)=%lf\n", &m_receiveLoss);fclose(pFile);
}void CJam::print_Jam_Param()
{printf("%d %d %d %d %d %d\n", m_jamPower, m_centerFreq, m_jamBand,\m_maxGain, m_transmitLoss, m_receiveLoss);
}
RadarParam.ini
[雷达参数]
峰值功率(kW)=5000
载频(MHz)=3300
天线最大增益(dB)=42
雷达系统综合损耗(dB)=6
接收机瞬时带宽(MHz)=10
噪声系数(dB)=3
虚警概率=0.000001
JamParam.ini
[干扰参数]
干扰功率(W)=5
中心频率(MHz)=3300
干扰带宽(MHz)=500
天线最大增益(dB)=10
干扰机发射综合损耗(dB)=3
雷达接收综合损耗(dB)=6
in.txt
1 300 10 -1 0
矩阵、坐标变换、相控阵天线拟合方向图代码相关推荐
- 相控阵天线面阵方向图(三种表示方法)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % 均匀面阵方向图的三种不同的表达式 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clc; close a ...
- 相控阵天线(一):直线阵列天线特性和阵列因子(方向图乘积定理、波束扫描、含python代码)
目录 方向图乘积定理 阵列因子方向图 波束扫描 阵列方向图和单元方向图 方向图乘积定理的python代码示例 方向图乘积定理 任意形式单元天线构成的直线阵如下图所示: 阵中第n个单元的远区辐射场可表示 ...
- 相控阵天线(四):阵列天线波束赋形(遗传算法、粒子群算法、进化差分算法、含python代码)
目录 波束赋形简介 遗传算法波束赋形 粒子群算法波束赋形 差分进化算法波束赋形 智能算法比较 遗传算法波束赋形代码示例 波束赋形简介 根据期望的方向图辐射特性(如方向图形状.主瓣宽度.副瓣电平.方向性 ...
- java布尔矩阵程序_Java编程实现邻接矩阵表示稠密图代码示例
我们知道,要表示结点,我们可以用一个一维数组来表示,然而对于结点和结点之间的关系,则无法简单地用一维数组来表示了,我们可以用二维数组来表示,也就是一个矩阵形式的表示方法. 我们假设A是这个二维数组,那 ...
- 相控阵天线(二):非规则直线阵列天线(稀布阵列、稀疏阵列、平方率分布阵列、含python代码)
目录 非规则线阵概述 不均匀递变间距阵列 稀布阵列 稀疏阵列 不均匀相位递变阵列 不均匀幅度激励阵列 代码示例 非规则线阵概述 非规则线阵主要包括以下情况: 1. 不均匀间距阵列: a)不均匀间距递变 ...
- 相控阵天线(十):波束跃度、虚位技术、幅度相位误差分析(含代码)
目录 简介 波束跃度 不同移相器位数对方向图的影响 不同移相器位数对波束跃度的影响 虚位技术 不同虚位位数对指向精度的影响 不同虚位位数对副瓣电平的影响 幅度相位误差分析 随机误差 周期误差 Pyth ...
- 相控阵天线(十二):天线校准技术仿真介绍之旋转矢量法
目录 简介 旋转矢量法算法介绍 旋转矢量法校准对方向图的影响 旋转矢量法算法仿真 移相器位数对旋转矢量法的影响 多通道旋转矢量法算法仿真 分区旋转矢量法算法仿真 简介 由于制造公差和天线互耦的影响,天 ...
- 相控阵天线低副瓣加权处理
相控阵天线低副瓣加权处理 1 辐射方向图低副瓣方法 1.1 幅度加权的基本原理 2 源代码 1 辐射方向图低副瓣方法 对于相控阵天线的辐射场,为了得到辐射方向图的低副瓣,常采用的方法有幅度加权,相位加 ...
- 相控阵天线之直线阵列综合
简介 可以参考我最新的博文相控阵天线(三):直线阵列天线低副瓣综合(切比雪夫.泰勒分布.SinZ-Z和Villeneuve分布.含python代码). 本博客对常见的直线阵列综合方式如:切比雪夫.泰勒 ...
最新文章
- delphi对窗体的查询(delphi xe2)
- python中importlib模块安装_importlib模块
- 21-matlab 迷宫题
- java进行md5运算(Java类函数调用)
- Ubuntu麒麟下搭建FTP服务
- JavaScript执行bat文件清理浏览器缓存
- Java 将File转换为MultipartFile类型
- 此版本的visual studio无法打开下列项目_深度学习实现高精度钢琴曲转谱Piano transcription项目简明使用教程...
- (C语言)用C语言编写小游戏——三子棋
- 没了珊瑚虫你用谁?八大QQ主流修改版大比拼
- android打印机驱动4521,三星SCX-4521打印机驱动
- 飞信机器人 ld-linux.so.2,飞信机器人安装
- QT - 图像处理 ( 1 ) - QImage像素级操作 - (转灰度、亮度、暖色、冷色、饱和度、模糊、锐化、金属效果 )
- 在线培训考核系统源码
- 如何区分嵌入式系统和嵌入式操作系统
- 音视频开发之旅(51)-M3U8边缓存边播放
- Linq to Sql 语句全集
- 【C语言】案例二十一 从键盘输入一组数据,求出这一组数据的平均值并输出(调用函数)
- java.sql.SQLException: Incorrect string value: '\xF0\x9F\x90\x9B],...' for column 'DESCR' at row 1问题
- vmware虚拟机官网下载的方法
热门文章
- 简单且强大的PHP调试工具 Kint
- ubuntu snap默认安装路径
- 的修报修系统是什么?的修报修系统好不好用?
- 嵌入式Qt-实现两个窗口的切换
- arduino编码器计数_关于电机中断计数问题 - Arduino - 极客工坊 - Powered by Discuz!...
- Windows安装arm64架构的麒麟V10
- FastAPI--参数提交Request Body(3)
- flutter 布局裁剪及实现微信聊天消息气泡组件
- 浅谈消防设备电源监控系统的设计与应用
- macos支持exfat吗_打造便捷、人性化的macOS桌面使用环境_软件应用