Repository navigation
Expand file tree
/
Copy pathsensoryPointCreate.cpp
More file actions
executable file
·201 lines (170 loc) · 7.74 KB
/
Copy pathsensoryPointCreate.cpp
File metadata and controls
executable file
·201 lines (170 loc) · 7.74 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*---------------------------------------------------------------------------*\
sensoryPointCreate.cpp
See header file for information on purpose
Copyright (c) 2004 R. Andrew Goodwin.
See license file for information on usage
\*---------------------------------------------------------------------------*/
#include "sensoryPointCreate.h"
using std::cout;
using std::endl;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void SensoryOvoid::createSensoryPoints
(
const int* FSOlimit,
double fishSensoryFieldVars_acclMagAtFish,
const int* nCoeff,
double coefficients[*nCoeff],
double fishBodyLengths_fishNumber,
int& validSVorient_XYZ_NPm1,
double& SV_angleOff_CFD_XYZ_NPm1,
double& ovoidLength,
double fishSP_angleOff_SV[*FSOlimit-2],
double SP_relative_XYZ[][3]
)
{
double sensoryOvoidX[*FSOlimit],
sensoryOvoidY[*FSOlimit],
sensoryOvoidZ[*FSOlimit];
double SPminDistance,
SP_XY_resultant,
SPangleOffCFD,
SPangleOffSV,
SPangleOffSVradian,
lengthFactor,
widenessFactor,
heigthFactor;
// First sensory point is the fish itself and, therefore, there is no
// displacement distance defined for this sensory point:
sensoryOvoidX[0] = 0.0;
sensoryOvoidY[0] = 0.0;
sensoryOvoidZ[0] = 0.0;
/* Other sensory points:
positive (+) "x" is in the direction the head of the fish is pointing
negative (-) "x" is in the direction of the fish's tail
positive (+) "y" is to the left of the fish
negative (-) "y" is to the right of the fish
positive (+) "z" is in the direction above the fish (adverse to gravity)
negative (-) "z" is in the direction below the fish (direction of gravity) */
SPminDistance = fishBodyLengths_fishNumber; // Body length
lengthFactor = coefficients[0];
widenessFactor = coefficients[1];
heigthFactor = coefficients[2];
// Sensory points are defined as a displacement distance of
// (x,y,z) = ( SENOVOIDX(fso),SENOVOIDY(fso),SENOVOIDZ(fso) )
// from the location of the fish
sensoryOvoidX[1] = SPminDistance * lengthFactor;
sensoryOvoidY[1] = 0;
sensoryOvoidZ[1] = 0;
sensoryOvoidX[2] = -SPminDistance * lengthFactor;
sensoryOvoidY[2] = 0;
sensoryOvoidZ[2] = 0;
sensoryOvoidX[3] = 0;
sensoryOvoidY[3] = SPminDistance * widenessFactor;
sensoryOvoidZ[3] = 0;
sensoryOvoidX[4] = 0;
sensoryOvoidY[4] = -SPminDistance * widenessFactor;
sensoryOvoidZ[4] = 0;
sensoryOvoidX[5] = 0;
sensoryOvoidY[5] = 0;
sensoryOvoidZ[5] = SPminDistance * heigthFactor;
sensoryOvoidX[6] = 0;
sensoryOvoidY[6] = 0;
sensoryOvoidZ[6] = -SPminDistance * heigthFactor;
// Set default values (fish facing in CFD x direction) ====================
ovoidLength = std::sqrt
(
(SPminDistance * lengthFactor)
* (SPminDistance * lengthFactor)
+ (SPminDistance * widenessFactor)
* (SPminDistance * widenessFactor)
+ (SPminDistance * heigthFactor)
* (SPminDistance * heigthFactor)
);
// Unused in BehaviorRule.f90 - requires transformation to fish coordinates
fishSP_angleOff_SV[0] = 0.0;
fishSP_angleOff_SV[1] = 0.0;
fishSP_angleOff_SV[2] = 180.0;
fishSP_angleOff_SV[3] = 90.0;
fishSP_angleOff_SV[4] = -90.0;
for (int FSO = 1; FSO < *FSOlimit; FSO++)
{
SP_relative_XYZ[FSO][0] = sensoryOvoidX[FSO]; // Distance (x-component in fish coordinates) from fish center to sensory point
SP_relative_XYZ[FSO][1] = sensoryOvoidY[FSO]; // Distance (y-component in fish coordinates) from fish center to sensory point
SP_relative_XYZ[FSO][2] = sensoryOvoidZ[FSO]; // Distance (z-component in fish coordinates) from fish center to sensory point
}
// Calculate Sensory Point Distances ======================================
// (i.e., that override the default distances) for actual fish orientation
// and/or if the SP were varied before. Introduces deviation in the
// 7th decimal place, probably due to approximation of pi, ignored.
if (validSVorient_XYZ_NPm1 == 1) // Valid xy-plane orientation of fish axis can be determined
{
for (int FSO = 1; FSO < *FSOlimit-2; FSO++) // Just for x/y-plane
{
SP_XY_resultant = std::sqrt
(
sensoryOvoidX[FSO]*sensoryOvoidX[FSO]
+sensoryOvoidY[FSO]*sensoryOvoidY[FSO]
);
// atan2 computes the arc tangent of y/x using the signs of arguments to
// determine the correct quadrant.
SPangleOffCFD = std::atan2
(
sensoryOvoidY[FSO],
sensoryOvoidX[FSO]
)
*(180.0/3.14159);
// Make ovoid angle relative to previous swim vector angle
SPangleOffSV = SPangleOffCFD + SV_angleOff_CFD_XYZ_NPm1;
// Perform bounds check
if (SPangleOffSV < 0.0)
{
SPangleOffSV += 360.0;
}
else if (SPangleOffSV > 360.0)
{
SPangleOffSV -= 360.0;
}
// Ensure that angles go from 0.0 to 180.0 and 0.0 to -180.0
if (SPangleOffSV > 180.0)
{
SPangleOffSV -= 360.0;
}
if (SPangleOffSV >= 0.0 && SPangleOffSV <= 90.0)
{
SPangleOffSVradian = SPangleOffSV * (3.14159/180.0);
SP_relative_XYZ[FSO][0] = SP_XY_resultant * std::cos(SPangleOffSVradian);
SP_relative_XYZ[FSO][1] = SP_XY_resultant * std::sin(SPangleOffSVradian);
}
else if (SPangleOffSV > 90.0 && SPangleOffSV <= 180.0)
{
SPangleOffSVradian = (180.0-SPangleOffSV) * (3.14159/180.0);
SP_relative_XYZ[FSO][0] = -SP_XY_resultant * std::cos(SPangleOffSVradian);
SP_relative_XYZ[FSO][1] = SP_XY_resultant * std::sin(SPangleOffSVradian);
}
else if (SPangleOffSV <= 0.0 && SPangleOffSV >= -90.0)
{
SPangleOffSVradian = -SPangleOffSV * (3.14159/180.0);
SP_relative_XYZ[FSO][0] = SP_XY_resultant * std::cos(SPangleOffSVradian);
SP_relative_XYZ[FSO][1] = -SP_XY_resultant * std::sin(SPangleOffSVradian);
}
else if (SPangleOffSV < -90.0 && SPangleOffSV >= -180.0)
{
SPangleOffSVradian = (180.0+SPangleOffSV) * (3.14159/180.0);
SP_relative_XYZ[FSO][0] = -SP_XY_resultant * std::cos(SPangleOffSVradian);
SP_relative_XYZ[FSO][1] = -SP_XY_resultant * std::sin(SPangleOffSVradian);
}
else
{
cout << " SPcreate.cpp: Improper SPangleOffSV value."
<< endl;
return;
}
} // End for FSO
} // End if validSVorient_XYZ_NPm1
else
{
cout << " SPcreate.cpp: Invalid xy orientation - falling back "
"to default SP relative distance" << endl;
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //