author | A.M. Thurnherr <athurnherr@yahoo.com> |
Thu, 07 May 2015 13:09:03 +0000 | |
changeset 23 | fb0c269b1eaa |
parent 19 | e23a5fd2923a |
child 28 | 7c7da52363c2 |
permissions | -rw-r--r-- |
0 | 1 |
#====================================================================== |
2 |
# R D I _ C O O R D S . P L |
|
3 |
# doc: Sun Jan 19 17:57:53 2003 |
|
19
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
4 |
# dlm: Thu May 29 09:19:54 2014 |
0 | 5 |
# (c) 2003 A.M. Thurnherr |
19
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
6 |
# uE-Info: 282 0 NIL 0 0 72 0 2 4 NIL ofnI |
0 | 7 |
#====================================================================== |
8 |
||
9 |
# RDI Workhorse Coordinate Transformations |
|
10 |
||
11 |
# HISTORY: |
|
12 |
# Jan 19, 2003: - written |
|
13 |
# Jan 21, 2003: - made it obey HEADING_BIAS (magnetic declination) |
|
14 |
# Jan 22, 3003: - corrected magnetic declination |
|
15 |
# Feb 16, 2003: - use pitch correction from RDI manual |
|
16 |
# Oct 11, 2003: - BUG: return value of atan() had been interpreted |
|
17 |
# as degrees instead of radians |
|
18 |
# Feb 27, 2004: - added velApplyHdgBias() |
|
19 |
# - changed non-zero HEADING_ALIGNMENT from error to warning |
|
20 |
# Sep 16, 2005: - added deg() for [mkprofile] |
|
21 |
# Aug 26, 2006: - BUG: incorrect transformation for uplookers |
|
22 |
# Nov 30, 2007: - optimized &velInstrumentToEarth(), velBeamToInstrument() |
|
23 |
# - added support for 3-beam solutions |
|
24 |
# Feb 12, 2008: - added threeBeamFlag |
|
25 |
# Mar 18, 2009: - added &gimbal_pitch(), &angle_from_vertical() |
|
26 |
# May 19, 2009: - added &velBeamToVertical() |
|
27 |
# May 23, 2009: - debugged & renamed to &velBeamToBPEarth |
|
28 |
# May 23, 2010: - changed prototypes of rad() & deg() to conform to ANTS |
|
5 | 29 |
# Dec 20, 2010: - cosmetics |
6 | 30 |
# Dec 23, 2010: - added &velBeamToBPInstrument |
31 |
# Jan 22, 2011: - made velApplyHdgBias calculate sin/cos every time to allow |
|
32 |
# per-ensemble corrections |
|
8 | 33 |
# Jan 15, 2012: - replaced defined(@...) by (@...) to get rid of warning |
13
b176da8559b3
before implementing WBWens (PD0 writing)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
8
diff
changeset
|
34 |
# Aug 7, 2013: - BUG: &velBeamToBPInstrument did not return any val unless |
b176da8559b3
before implementing WBWens (PD0 writing)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
8
diff
changeset
|
35 |
# all beam velocities are defined |
14 | 36 |
# Nov 27, 2013: - added &RDI_pitch(), &tilt_azimuth() |
19
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
37 |
# Mar 4, 2014: - added support for ensembles with missing PITCH/ROLL/HEADING |
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
38 |
# May 29, 2014: - BUG: vertical velocity can be calculated even without |
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
39 |
# heading |
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
40 |
# - removed some old debug statements |
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
41 |
# - removed unused code from &velBeamToBPInstrument |
0 | 42 |
|
43 |
use strict; |
|
44 |
use POSIX; |
|
45 |
||
46 |
my($PI) = 3.14159265358979; |
|
47 |
||
48 |
sub rad(@) { return $_[0]/180 * $PI; } |
|
49 |
sub deg(@) { return $_[0]/$PI * 180; } |
|
50 |
||
51 |
$RDI_Coords::minValidVels = 3; # 3-beam solutions ok |
|
52 |
||
53 |
$RDI_Coords::threeBeam_1 = 0; # stats |
|
54 |
$RDI_Coords::threeBeam_2 = 0; |
|
55 |
$RDI_Coords::threeBeam_3 = 0; |
|
56 |
$RDI_Coords::threeBeam_4 = 0; |
|
57 |
$RDI_Coords::fourBeam = 0; |
|
58 |
||
59 |
$RDI_Coords::threeBeamFlag = 0; # flag last transformation |
|
60 |
||
61 |
{ # STATIC SCOPE |
|
62 |
my(@B2I); |
|
63 |
||
64 |
sub velBeamToInstrument(@) |
|
65 |
{ |
|
66 |
my($dta,$v1,$v2,$v3,$v4) = @_; |
|
67 |
return undef unless (defined($v1) + defined($v2) + |
|
68 |
defined($v3) + defined($v4) |
|
69 |
>= $RDI_Coords::minValidVels); |
|
70 |
||
8 | 71 |
unless (@B2I) { |
0 | 72 |
my($a) = 1 / (2 * sin(rad($dta->{BEAM_ANGLE}))); |
73 |
my($b) = 1 / (4 * cos(rad($dta->{BEAM_ANGLE}))); |
|
74 |
my($c) = $dta->{CONVEX_BEAM_PATTERN} ? 1 : -1; |
|
75 |
my($d) = $a / sqrt(2); |
|
76 |
@B2I = ([$c*$a, -$c*$a, 0, 0 ], |
|
77 |
[0, 0, -$c*$a, $c*$a], |
|
78 |
[$b, $b, $b, $b ], |
|
79 |
[$d, $d, -$d, -$d ]); |
|
80 |
} |
|
81 |
||
82 |
if (!defined($v1)) { # 3-beam solutions |
|
83 |
$RDI_Coords::threeBeamFlag = 1; |
|
84 |
$RDI_Coords::threeBeam_1++; |
|
85 |
$v1 = -($v2*$B2I[3][1]+$v3*$B2I[3][2]+$v4*$B2I[3][3])/$B2I[3][0]; |
|
86 |
} elsif (!defined($v2)) { |
|
87 |
$RDI_Coords::threeBeamFlag = 1; |
|
88 |
$RDI_Coords::threeBeam_2++; |
|
89 |
$v2 = -($v1*$B2I[3][0]+$v3*$B2I[3][2]+$v4*$B2I[3][3])/$B2I[3][1]; |
|
90 |
} elsif (!defined($v3)) { |
|
91 |
$RDI_Coords::threeBeamFlag = 1; |
|
92 |
$RDI_Coords::threeBeam_3++; |
|
93 |
$v3 = -($v1*$B2I[3][0]+$v2*$B2I[3][1]+$v4*$B2I[3][3])/$B2I[3][2]; |
|
94 |
} elsif (!defined($v4)) { |
|
95 |
$RDI_Coords::threeBeamFlag = 1; |
|
96 |
$RDI_Coords::threeBeam_4++; |
|
97 |
$v4 = -($v1*$B2I[3][0]+$v2*$B2I[3][1]+$v3*$B2I[3][2])/$B2I[3][3]; |
|
98 |
} else { |
|
99 |
$RDI_Coords::threeBeamFlag = 0; |
|
100 |
$RDI_Coords::fourBeam++; |
|
101 |
} |
|
102 |
||
103 |
return ($v1*$B2I[0][0]+$v2*$B2I[0][1], |
|
104 |
$v3*$B2I[1][2]+$v4*$B2I[1][3], |
|
105 |
$v1*$B2I[2][0]+$v2*$B2I[2][1]+$v3*$B2I[2][2]+$v4*$B2I[2][3], |
|
106 |
$v1*$B2I[3][0]+$v2*$B2I[3][1]+$v3*$B2I[3][2]+$v4*$B2I[3][3]); |
|
107 |
} |
|
108 |
} # STATIC SCOPE |
|
109 |
||
110 |
{ # STATIC SCOPE |
|
111 |
my($hdg,$pitch,$roll,@I2E); |
|
112 |
||
113 |
sub velInstrumentToEarth(@) |
|
114 |
{ |
|
115 |
my($dta,$ens,$v1,$v2,$v3,$v4) = @_; |
|
116 |
return undef unless (defined($v1) && defined($v2) && |
|
18 | 117 |
defined($v3) && defined($v4) && |
118 |
defined($dta->{ENSEMBLE}[$ens]->{PITCH}) && |
|
19
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
119 |
defined($dta->{ENSEMBLE}[$ens]->{ROLL})); |
0 | 120 |
|
121 |
unless (@I2E && |
|
122 |
$pitch == $dta->{ENSEMBLE}[$ens]->{PITCH} && |
|
123 |
$roll == $dta->{ENSEMBLE}[$ens]->{ROLL}) { |
|
124 |
printf(STDERR "$0: warning HEADING_ALIGNMENT == %g ignored\n", |
|
125 |
$dta->{HEADING_ALIGNMENT}) |
|
126 |
if ($dta->{HEADING_ALIGNMENT}); |
|
19
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
127 |
$hdg = $dta->{ENSEMBLE}[$ens]->{HEADING} - $dta->{HEADING_BIAS} |
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
128 |
if defined($dta->{ENSEMBLE}[$ens]->{HEADING}); |
0 | 129 |
$pitch = $dta->{ENSEMBLE}[$ens]->{PITCH}; |
130 |
$roll = $dta->{ENSEMBLE}[$ens]->{ROLL}; |
|
131 |
my($rad_gimbal_pitch) = atan(tan(rad($pitch)) * cos(rad($roll))); |
|
19
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
132 |
my($sh,$ch) = (sin(rad($hdg)),cos(rad($hdg))) |
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
133 |
if defined($hdg); |
0 | 134 |
my($sp,$cp) = (sin($rad_gimbal_pitch),cos($rad_gimbal_pitch)); |
135 |
my($sr,$cr) = (sin(rad($roll)), cos(rad($roll))); |
|
136 |
@I2E = $dta->{ENSEMBLE}[$ens]->{XDUCER_FACING_UP} |
|
137 |
? ( |
|
138 |
[-$ch*$cr-$sh*$sp*$sr, $sh*$cp,-$ch*$sr+$sh*$sp*$cr], |
|
139 |
[-$ch*$sp*$sr+$sh*$cr, $ch*$cp, $sh*$sr+$ch*$sp*$cr], |
|
140 |
[+$cp*$sr, $sp, -$cp*$cr, ], |
|
141 |
) : ( |
|
142 |
[$ch*$cr+$sh*$sp*$sr, $sh*$cp, $ch*$sr-$sh*$sp*$cr], |
|
143 |
[$ch*$sp*$sr-$sh*$cr, $ch*$cp,-$sh*$sr-$ch*$sp*$cr], |
|
144 |
[-$cp*$sr, $sp, $cp*$cr, ], |
|
145 |
); |
|
146 |
} |
|
19
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
147 |
return defined($dta->{ENSEMBLE}[$ens]->{HEADING}) |
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
148 |
? ($v1*$I2E[0][0]+$v2*$I2E[0][1]+$v3*$I2E[0][2], |
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
149 |
$v1*$I2E[1][0]+$v2*$I2E[1][1]+$v3*$I2E[1][2], |
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
150 |
$v1*$I2E[2][0]+$v2*$I2E[2][1]+$v3*$I2E[2][2], |
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
151 |
$v4) |
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
152 |
: (undef,undef, |
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
153 |
$v1*$I2E[2][0]+$v2*$I2E[2][1]+$v3*$I2E[2][2], |
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
154 |
$v4); |
0 | 155 |
} |
156 |
} # STATIC SCOPE |
|
157 |
||
158 |
#====================================================================== |
|
5 | 159 |
# velBeamToBPEarth(@) calculates the vertical- and horizontal vels |
0 | 160 |
# from the two beam pairs separately. Note that (w1+w2)/2 is |
161 |
# identical to the w estimated according to RDI without 3-beam |
|
162 |
# solutions. |
|
163 |
#====================================================================== |
|
164 |
||
165 |
{ # STATIC SCOPE |
|
166 |
my($TwoCosBAngle,$TwoSinBAngle); |
|
167 |
||
168 |
sub velBeamToBPEarth(@) |
|
169 |
{ |
|
170 |
my($dta,$ens,$b1,$b2,$b3,$b4) = @_; |
|
171 |
my($v12,$w12,$v34,$w34); |
|
172 |
||
18 | 173 |
return (undef,undef,undef,undef) |
174 |
unless (defined($dta->{ENSEMBLE}[$ens]->{PITCH}) && |
|
19
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
175 |
defined($dta->{ENSEMBLE}[$ens]->{ROLL})); |
18 | 176 |
|
0 | 177 |
unless (defined($TwoCosBAngle)) { |
178 |
$TwoCosBAngle = 2 * cos(rad($dta->{BEAM_ANGLE})); |
|
179 |
$TwoSinBAngle = 2 * sin(rad($dta->{BEAM_ANGLE})); |
|
180 |
} |
|
181 |
my($roll) = rad($dta->{ENSEMBLE}[$ens]->{ROLL}); |
|
182 |
my($sr) = sin($roll); my($cr) = cos($roll); |
|
183 |
my($pitch) = atan(tan(rad($dta->{ENSEMBLE}[$ens]->{PITCH})) * $cr); # gimbal pitch |
|
184 |
my($sp) = sin($pitch); my($cp) = cos($pitch); |
|
185 |
||
186 |
# Sign convention: |
|
187 |
# - refer to Coord manual Fig. 3 |
|
188 |
# - v12 is horizontal velocity from beam1 to beam2, i.e. westward for upward-looking ADCP |
|
189 |
# with beam 3 pointing north (heading = 0) |
|
190 |
# - w is +ve upward, regardless of instrument orientation |
|
191 |
||
192 |
my($v12_ic) = ($b1-$b2)/$TwoSinBAngle; # instrument coords with w vertical up |
|
193 |
my($w12_ic) = ($b1+$b2)/$TwoCosBAngle; |
|
194 |
$w12_ic *= -1 if ($dta->{ENSEMBLE}[$ens]->{XDUCER_FACING_UP}); |
|
195 |
my($v34_ic) = ($b3-$b4)/$TwoSinBAngle; |
|
196 |
my($w34_ic) = ($b3+$b4)/$TwoCosBAngle; |
|
197 |
$w34_ic *= -1 if ($dta->{ENSEMBLE}[$ens]->{XDUCER_FACING_UP}); |
|
198 |
||
199 |
if ($dta->{ENSEMBLE}[$ens]->{XDUCER_FACING_UP}) { # beampair Earth coords |
|
200 |
$w12 = $w12_ic*$cr + $v12_ic*$sr - $v34_ic*$sp; |
|
201 |
$v12 = $v12_ic*$cr - $w12_ic*$sr + $w34_ic*$sp; |
|
202 |
$w34 = $w34_ic*$cp - $v34_ic*$sp + $v12_ic*$sr; |
|
203 |
$v34 = $v34_ic*$cp + $w34_ic*$sp - $w12_ic*$sr; |
|
204 |
} else { |
|
205 |
$w12 = $w12_ic*$cr - $v12_ic*$sr - $v34_ic*$sp; |
|
206 |
$v12 = $v12_ic*$cr + $w12_ic*$sr + $w34_ic*$sp; |
|
207 |
$w34 = $w34_ic*$cp - $v34_ic*$sp - $v12_ic*$sr; |
|
208 |
$v34 = $v34_ic*$cp + $w34_ic*$sp + $w12_ic*$sr; |
|
209 |
} |
|
210 |
||
13
b176da8559b3
before implementing WBWens (PD0 writing)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
8
diff
changeset
|
211 |
$v12=$w12=undef unless (defined($b1) && defined($b2)); |
b176da8559b3
before implementing WBWens (PD0 writing)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
8
diff
changeset
|
212 |
$v34=$w34=undef unless (defined($b3) && defined($b4)); |
b176da8559b3
before implementing WBWens (PD0 writing)
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
8
diff
changeset
|
213 |
|
0 | 214 |
return ($v12,$w12,$v34,$w34); |
215 |
} |
|
216 |
} |
|
217 |
||
5 | 218 |
#=================================================================== |
219 |
# velBeamToBPInstrument(@) calculates the instrument-coordinate vels |
|
220 |
# from the two beam pairs separately. |
|
221 |
#=================================================================== |
|
222 |
||
223 |
{ # STATIC SCOPE |
|
224 |
my($TwoCosBAngle,$TwoSinBAngle); |
|
225 |
||
226 |
sub velBeamToBPInstrument(@) |
|
227 |
{ |
|
228 |
my($dta,$ens,$b1,$b2,$b3,$b4) = @_; |
|
229 |
my($v12,$w12,$v34,$w34); |
|
230 |
||
18 | 231 |
return (undef,undef,undef,undef) |
232 |
unless (defined($dta->{ENSEMBLE}[$ens]->{PITCH}) && |
|
19
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
18
diff
changeset
|
233 |
defined($dta->{ENSEMBLE}[$ens]->{ROLL})); |
18 | 234 |
|
5 | 235 |
unless (defined($TwoCosBAngle)) { |
236 |
$TwoCosBAngle = 2 * cos(rad($dta->{BEAM_ANGLE})); |
|
237 |
$TwoSinBAngle = 2 * sin(rad($dta->{BEAM_ANGLE})); |
|
238 |
} |
|
239 |
||
240 |
# Sign convention: |
|
241 |
# - refer to Coord manual Fig. 3 |
|
242 |
# - v12 is horizontal velocity from beam1 to beam2 |
|
243 |
# - w is +ve upward, regardless of instrument orientation |
|
244 |
||
245 |
if (defined($b1) && defined($b2)) { |
|
246 |
$v12 = ($b1-$b2)/$TwoSinBAngle; |
|
247 |
$w12 = ($b1+$b2)/$TwoCosBAngle; |
|
248 |
$w12 *= -1 if ($dta->{ENSEMBLE}[$ens]->{XDUCER_FACING_UP}); |
|
249 |
} |
|
250 |
if (defined($b3) && defined($b4)) { |
|
251 |
$v34 = ($b3-$b4)/$TwoSinBAngle; |
|
252 |
$w34 = ($b3+$b4)/$TwoCosBAngle; |
|
253 |
$w34 *= -1 if ($dta->{ENSEMBLE}[$ens]->{XDUCER_FACING_UP}); |
|
254 |
} |
|
255 |
||
256 |
return ($v12,$w12,$v34,$w34); |
|
257 |
} |
|
258 |
} |
|
259 |
||
0 | 260 |
#====================================================================== |
261 |
# velApplyHdgBias() applies the heading bias, which is used to correct |
|
262 |
# for magnetic declination for data recorded in Earth-coordinates ONLY. |
|
263 |
# Bias correction for beam-coordinate data is done in velInstrumentToEarth() |
|
264 |
#====================================================================== |
|
265 |
||
6 | 266 |
sub velApplyHdgBias(@) |
267 |
{ |
|
268 |
my($dta,$ens,$v1,$v2,$v3,$v4) = @_; |
|
18 | 269 |
return (undef,undef,undef,undef) |
270 |
unless (defined($v1) && defined($v2) && |
|
271 |
defined($dta->{ENSEMBLE}[$ens]->{HEADING})); |
|
0 | 272 |
|
6 | 273 |
my($sh) = sin(rad(-$dta->{HEADING_BIAS})); |
274 |
my($ch) = cos(rad(-$dta->{HEADING_BIAS})); |
|
0 | 275 |
|
6 | 276 |
return ( $v1*$ch + $v2*$sh, |
277 |
-$v1*$sh + $v2*$ch, |
|
278 |
$v3 , |
|
279 |
$v4 ); |
|
280 |
} |
|
0 | 281 |
|
282 |
#---------------------------------------------------------------------- |
|
283 |
# Pitch/Roll Functions |
|
284 |
#---------------------------------------------------------------------- |
|
285 |
||
286 |
sub gimbal_pitch($$) # RDI coord trans manual |
|
287 |
{ |
|
5 | 288 |
my($RDI_pitch,$RDI_roll) = @_; |
18 | 289 |
return 'nan' unless defined($RDI_pitch) && defined($RDI_roll); |
5 | 290 |
return deg(atan(tan(rad($RDI_pitch)) * cos(rad($RDI_roll)))); |
0 | 291 |
} |
292 |
||
14 | 293 |
sub RDI_pitch($$) |
294 |
{ |
|
295 |
my($gimbal_pitch,$roll) = @_; |
|
18 | 296 |
return 'nan' unless defined($gimbal_pitch) && defined($roll); |
14 | 297 |
return deg(atan(tan(rad($gimbal_pitch))/cos(rad($roll)))); |
298 |
} |
|
299 |
||
300 |
sub tilt_azimuth($$) |
|
301 |
{ |
|
302 |
my($gimbal_pitch,$roll) = @_; |
|
18 | 303 |
return 'nan' unless defined($gimbal_pitch) && defined($roll); |
14 | 304 |
return angle(deg(atan2(sin(rad($gimbal_pitch)),sin(rad($roll))))); |
305 |
} |
|
306 |
||
18 | 307 |
# - angle from vertical is home grown |
0 | 308 |
# - angle between two unit vectors given by acos(v1 dot v2) |
309 |
# - vertical unit vector v1 = (0 0 1) => dot product = z-component of v2 |
|
310 |
# - when vertical unit vector is pitched in x direction, followed by |
|
311 |
# roll in y direction: |
|
312 |
# x = sin(pitch) |
|
313 |
# y = cos(pitch) * sin(roll) |
|
314 |
# z = cos(pitch) * cos(roll) |
|
315 |
# has been checked with sqrt(x^2+y^2+z^2) == 1 |
|
316 |
# - for small angles, this is very similar to sqrt(pitch^2+roll^2) |
|
317 |
||
318 |
sub angle_from_vertical($$) |
|
319 |
{ |
|
5 | 320 |
my($RDI_pitch,$RDI_roll) = @_; |
18 | 321 |
return 'nan' unless defined($RDI_pitch) && defined($RDI_roll); |
5 | 322 |
my($rad_pitch) = atan(tan(rad($RDI_pitch)) * cos(rad($RDI_roll))); |
323 |
return deg(acos(cos($rad_pitch) * cos(rad($RDI_roll)))); |
|
0 | 324 |
} |
325 |
||
326 |
1; |