comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java @ 334:b7c8df643dc4

Discharge table: we need a getQForW() and not a getWForQ(). flys-artifacts/trunk@1732 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 19 Apr 2011 17:37:21 +0000
parents 67b3f54188aa
children 7f13ed751277
comparison
equal deleted inserted replaced
333:67b3f54188aa 334:b7c8df643dc4
178 } 178 }
179 179
180 return values; 180 return values;
181 } 181 }
182 182
183 public static boolean getWForQ( 183 public static double getQForW(
184 double [][] values, 184 double [][] values,
185 double q, 185 double w,
186 double [] result 186 double [] result
187 ) { 187 ) {
188 int index = Arrays.binarySearch(values[1], q); 188 int index = Arrays.binarySearch(values[0], w);
189 if (index >= 0) { 189 if (index >= 0) {
190 result[0] = values[1][index]; 190 return values[0][index];
191 return true;
192 } 191 }
193 192
194 index = -index - 1; // insert position 193 index = -index - 1; // insert position
195 194
196 if (index == 0 || index+1 >= values.length) { 195 if (index < 1 || index >= values.length) {
197 // do not extraploate 196 // do not extraploate
198 return false; 197 return Double.NaN;
199 } 198 }
200 199
201 double q1 = values[index ][0]; 200 double w1 = values[index-1][0];
202 double q2 = values[index+1][0]; 201 double w2 = values[index ][0];
203 double w1 = values[index ][1]; 202 double q1 = values[index-1][1];
204 double w2 = values[index+1][1]; 203 double q2 = values[index ][1];
205 204
206 // w1 = m*q1 + b 205 // q1 = m*w1 + b
207 // w2 = m*q2 + b 206 // q2 = m*w2 + b
208 // w2 - w1 = m*(q2 - q1) 207 // q2 - q1 = m*(w2 - w1)
209 // m = (w2 - w1)/(q2 - q1) # q2 != q1 208 // m = (q2 - q1)/(w2 - w1) # w2 != w1
210 // b = w1 - m*q1 209 // b = q1 - m*w1
211 210
212 if (q1 == q2) { 211 if (w1 == w2) {
213 result[0] = 0.5*(w1 + w2); 212 return 0.5*(q1 + q2);
214 } 213 }
215 else { 214
216 double m = (w2 - w1)/(q2 - q1); 215 double m = (q2 - q1)/(w2 - w1);
217 double b = w1 - m*q1; 216 double b = q1 - m*w1;
218 result[0] = q*m + b; 217 return w*m + b;
219 }
220
221 return true;
222 } 218 }
223 } 219 }
224 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 220 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org