-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsensor2D.h
More file actions
129 lines (124 loc) · 3.1 KB
/
sensor2D.h
File metadata and controls
129 lines (124 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#pragma once
#include<iostream>
#include "parameters.h"
using namespace std;
class sensor2D {
public:
double b;
double c;
double h_max;
double h_flight;
double position;
// double time;
double k;
double j;
double v; //速度
double calx; //累计横坐标
double dataAmount;
double* RofDifferentHeight; //存储不同高度下的范围半径的数组
int heightOfMaxR; //范围半径最大的高度对应的高度下标
sensor2D() {
b = 0;
c = 0;
h_max = 0;
h_flight = 0;
position = 0;
dataAmount = 0;
v = 0;
RofDifferentHeight = new double[HEIGHT_BOUNDARY / DELTA_H + 1];
heightOfMaxR = 1;
}
sensor2D(double b, double c, double x, double amount) {
init(b, c, x, amount);
}
void init(double b, double c, double x, double amount) {
this->b = b;
this->c = c;
h_max = b;
position = x;
dataAmount = amount;
h_flight = 0;
v = -1;
calx = 0;
RofDifferentHeight = new double[HEIGHT_BOUNDARY / DELTA_H + 1];
heightOfMaxR = 1;
}
void show(void)
{
cout << b << '\t' << c << '\t' << position << '\t' << dataAmount << endl;
}
void setPosition(double x)
{
position = x;
}
void calculateR()
{
int i = 1;
double hCal = DELTA_H;
RofDifferentHeight[i] = 0;
while (hCal < b)
{
// double a[5] = { pow(hCal,4) - b * pow(hCal,3), 0, 2 * hCal * hCal - b * hCal + c, 0, 1 };
/*
double a[5] = { 1, 0, 2 * hCal * hCal - b * hCal + c, 0, pow(hCal,4) - b * pow(hCal,3) };
double z[8];
gsl_poly_complex_workspace* w = gsl_poly_complex_workspace_alloc(5);
gsl_poly_complex_solve(a, 5, w, z);
gsl_poly_complex_workspace_free(w);
RofDifferentHeight[i] = abs(z[1] - z[3]) / 2;
*/
// 解两次一元二次方程
double aOfEquation = 1;
double bOfEquation = 2 * hCal * hCal - b * hCal + c;
double cOfEquation = pow(hCal, 4) - b * pow(hCal, 3);
// cout << "bOfEquation: " << bOfEquation << " ; cOfEquati0on" << cOfEquation << endl;
double delta = bOfEquation * bOfEquation - 4 * aOfEquation * cOfEquation;
// 判别式小于0,无实根
if (delta - 0 < EPSLION)
{
cout << "there is something wrong when calculating the R." << endl;
return;
}
//判别式不小于0
else
{
//判别式等于0
if (delta - 0 == EPSLION)
{
if (-bOfEquation / (2 * aOfEquation) - 0 < EPSLION)
{
cout << "there is something wrong when calculating the R." << endl;
return;
}
else
RofDifferentHeight[i] = sqrt(-bOfEquation / (2 * aOfEquation));
}
// 判别式大于零 两个实数解
else
{
double x1 = (-bOfEquation + sqrt(delta)) / (2 * aOfEquation);
double x2 = (-bOfEquation - sqrt(delta)) / (2 * aOfEquation);
if (x1 < 0 || x2 >0)
{
cout << "there is something wrong when calculating the R." << endl;
return;
}
else
{
RofDifferentHeight[i] = sqrt(x1);
}
}
//验证一下计算结果是否正确
double y = RofDifferentHeight[i];
/*
double res = pow(hCal * hCal + y * y, 2) - b * hCal * (hCal * hCal + y * y) + c * y * y;
cout << "result = " << res << endl;
*/
}
if (RofDifferentHeight[i] >= RofDifferentHeight[heightOfMaxR]) heightOfMaxR = i;
else break;
i++;
hCal = hCal + DELTA_H;
}
}
};