Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/math/LinearFunction.java @ 850:39d06d01825a
Finalized the odv export of a 'Profilschnitt' (issue217).
gnv-artifacts/trunk@966 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 21 Apr 2010 12:34:44 +0000 |
parents | a645bd23c1c8 |
children | f953c9a559d8 |
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.FunctionEvaluationException; |
25e4724aa504
Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 |
433
828df3ddb758
Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
357
diff
changeset
|
5 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
|
6 |
779
b1f5f2a8840f
Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
7 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
|
8 |
357
25e4724aa504
Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 /** |
807
a645bd23c1c8
Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
805
diff
changeset
|
10 * 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
|
11 * the Apache Commons Mathematics Library. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
780
diff
changeset
|
12 * |
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
|
13 * @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
|
14 */ |
25e4724aa504
Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 public class LinearFunction |
25e4724aa504
Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 implements ParametricRealFunction |
25e4724aa504
Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 { |
805
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
780
diff
changeset
|
18 /** |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
780
diff
changeset
|
19 * 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
|
20 */ |
357
25e4724aa504
Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 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
|
22 |
805
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
780
diff
changeset
|
23 /** |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
780
diff
changeset
|
24 * 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
|
25 * in the Apache Commons Mathematics Library. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
780
diff
changeset
|
26 */ |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
514
diff
changeset
|
27 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
|
28 implements UnivariateRealFunction |
828df3ddb758
Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
357
diff
changeset
|
29 { |
805
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
780
diff
changeset
|
30 /** |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
780
diff
changeset
|
31 * The linear scaling factor. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
780
diff
changeset
|
32 */ |
433
828df3ddb758
Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
357
diff
changeset
|
33 protected double m; |
805
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
780
diff
changeset
|
34 /** |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
780
diff
changeset
|
35 * The linear offset. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
780
diff
changeset
|
36 */ |
433
828df3ddb758
Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
357
diff
changeset
|
37 protected double b; |
828df3ddb758
Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
357
diff
changeset
|
38 |
805
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
780
diff
changeset
|
39 /** |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
780
diff
changeset
|
40 * Default constructor. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
780
diff
changeset
|
41 */ |
433
828df3ddb758
Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
357
diff
changeset
|
42 public Univariate() { |
828df3ddb758
Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
357
diff
changeset
|
43 } |
828df3ddb758
Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
357
diff
changeset
|
44 |
805
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
780
diff
changeset
|
45 /** |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
780
diff
changeset
|
46 * 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
|
47 * 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
|
48 * @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
|
49 * @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
|
50 * @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
|
51 * @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
|
52 */ |
433
828df3ddb758
Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
357
diff
changeset
|
53 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
|
54 if (y1 == y2) { |
828df3ddb758
Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
357
diff
changeset
|
55 m = 0d; |
828df3ddb758
Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
357
diff
changeset
|
56 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
|
57 } |
828df3ddb758
Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
357
diff
changeset
|
58 else { |
828df3ddb758
Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
357
diff
changeset
|
59 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
|
60 b = y1 - m*x1; |
828df3ddb758
Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
357
diff
changeset
|
61 } |
828df3ddb758
Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
357
diff
changeset
|
62 } |
828df3ddb758
Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
357
diff
changeset
|
63 |
828df3ddb758
Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
357
diff
changeset
|
64 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
|
65 return m*x + b; |
828df3ddb758
Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
357
diff
changeset
|
66 } |
828df3ddb758
Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
357
diff
changeset
|
67 } // class Univariate |
828df3ddb758
Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
357
diff
changeset
|
68 |
805
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
780
diff
changeset
|
69 /** |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
780
diff
changeset
|
70 * Default constructor. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
780
diff
changeset
|
71 */ |
357
25e4724aa504
Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 public LinearFunction() { |
25e4724aa504
Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 } |
25e4724aa504
Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 |
25e4724aa504
Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 public double value(double x, double [] parameters) |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
514
diff
changeset
|
76 throws FunctionEvaluationException |
357
25e4724aa504
Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 { |
25e4724aa504
Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 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
|
79 } |
25e4724aa504
Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
514
diff
changeset
|
81 public double [] gradient(double x, double [] parameters) |
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
514
diff
changeset
|
82 throws FunctionEvaluationException |
357
25e4724aa504
Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 { |
25e4724aa504
Fill (i, j)-gaps when building index buffer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 return new double [] { x, 1f }; |
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 } |
514
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
433
diff
changeset
|
87 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |