annotate gnv-artifacts/src/main/java/de/intevation/gnv/math/LinearFunction.java @ 1115:f953c9a559d8

Added license file and license headers. gnv-artifacts/trunk@1260 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 02 Nov 2010 17:46:55 +0000
parents a645bd23c1c8
children
rev   line source
1115
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 807
diff changeset
1 /*
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 807
diff changeset
2 * Copyright (c) 2010 by Intevation GmbH
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 807
diff changeset
3 *
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 807
diff changeset
4 * This program is free software under the LGPL (>=v2.1)
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 807
diff changeset
5 * Read the file LGPL.txt coming with the software for details
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 807
diff changeset
6 * or visit http://www.gnu.org/licenses/ if it does not exist.
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 807
diff changeset
7 */
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 807
diff changeset
8
357
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 package de.intevation.gnv.math;
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 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
12
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
13 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
14
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
15 import org.apache.commons.math.optimization.fitting.ParametricRealFunction;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
16
357
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 /**
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 805
diff changeset
18 * Models a linear function to be usable in the fitting framework of
805
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
19 * the Apache Commons Mathematics Library.
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
20 *
780
c4156275c1e1 Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 779
diff changeset
21 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a>
357
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 */
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 public class LinearFunction
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 implements ParametricRealFunction
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 {
805
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
26 /**
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
27 * Instance to prevent needless creations of instances.
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
28 */
357
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 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
30
805
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
31 /**
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
32 * Specialized class to be useful in function evaluating
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
33 * in the Apache Commons Mathematics Library.
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
34 */
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
35 public static class Univariate
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
36 implements UnivariateRealFunction
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
37 {
805
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
38 /**
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
39 * The linear scaling factor.
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
40 */
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
41 protected double m;
805
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
42 /**
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
43 * The linear offset.
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
44 */
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
45 protected double b;
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
46
805
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
47 /**
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
48 * Default constructor.
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
49 */
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
50 public Univariate() {
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
51 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
52
805
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
53 /**
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
54 * Constructor to create a Univariate with the linear parameters
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
55 * of the line between (x1, y1) and (x2, y2).
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
56 * @param x1 The x coordinate of the first point.
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
57 * @param y1 The y coordinate of the first point.
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
58 * @param x2 The x coordinate of the second point.
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
59 * @param y2 The y coordinate of the second point.
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
60 */
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
61 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
62 if (y1 == y2) {
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
63 m = 0d;
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
64 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
65 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
66 else {
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
67 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
68 b = y1 - m*x1;
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
69 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
70 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
71
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
72 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
73 return m*x + b;
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
74 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
75 } // class Univariate
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 357
diff changeset
76
805
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
77 /**
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
78 * Default constructor.
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
79 */
357
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
80 public LinearFunction() {
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
81 }
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
82
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
83 public double value(double x, double [] parameters)
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
84 throws FunctionEvaluationException
357
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
85 {
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
86 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
87 }
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
89 public double [] gradient(double x, double [] parameters)
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
90 throws FunctionEvaluationException
357
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91 {
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92 return new double [] { x, 1f };
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93 }
25e4724aa504 Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94 }
514
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 433
diff changeset
95 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org