annotate gnv-artifacts/src/main/java/de/intevation/gnv/math/LinearFunction.java @ 503:b951b14425fa

Solved issue 129. Renamed i and j axis to 'West-East-Axis' and 'North-South-Axis'. gnv-artifacts/trunk@586 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 20 Jan 2010 15:48:31 +0000
parents 828df3ddb758
children d9d933e06875
rev   line source
357
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.gnv.math;
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import org.apache.commons.math.optimization.fitting.ParametricRealFunction;
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 import org.apache.commons.math.FunctionEvaluationException;
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
7 import org.apache.commons.math.analysis.UnivariateRealFunction;
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
8
357
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 /**
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 * @author Sascha L. Teichmann
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 */
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 public class LinearFunction
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 implements ParametricRealFunction
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 {
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 public static final LinearFunction INSTANCE = new LinearFunction();
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
17 public static class Univariate
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
18 implements UnivariateRealFunction
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
19 {
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
20 protected double m;
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
21 protected double b;
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
22
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
23 public Univariate() {
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
24 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
25
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
26 public Univariate(double x1, double y1, double x2, double y2) {
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
27 if (y1 == y2) {
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
28 m = 0d;
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
29 b = (x1 + x2)*0.5d;
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
30 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
31 else {
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
32 m = (x1 - x2)/(y1 - y2);
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
33 b = y1 - m*x1;
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
34 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
35 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
36
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
37 public double value(double x) {
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
38 return m*x + b;
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
39 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
40 } // class Univariate
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
41
357
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 public LinearFunction() {
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 }
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 public double value(double x, double [] parameters)
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 throws FunctionEvaluationException
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 {
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 return x*parameters[0] + parameters[1];
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 }
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 public double [] gradient(double x, double [] parameters)
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 throws FunctionEvaluationException
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 {
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 return new double [] { x, 1f };
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 }
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 }
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org