Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/math/LinearMetrics.java @ 1142:12abbf15f18a
dummy merge for repo head
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:15:20 +0200 |
parents | f953c9a559d8 |
children |
rev | line source |
---|---|
1115
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
1 /* |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
2 * Copyright (c) 2010 by Intevation GmbH |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
3 * |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
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:
836
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:
836
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:
836
diff
changeset
|
7 */ |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
836
diff
changeset
|
8 |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 package de.intevation.gnv.math; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
361
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
360
diff
changeset
|
11 import com.vividsolutions.jts.geom.Coordinate; |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 /** |
805
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
14 * Implements {@link de.intevation.gnv.math.Metrics} |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
15 * for linear interpolations and distance measurements. |
798
6cff63d0c434
Fixed vim modeline. Added some Javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
361
diff
changeset
|
16 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 */ |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 public final class LinearMetrics |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 implements Metrics |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 { |
805
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
21 /** |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
22 * Instance to prevent needless creations of instances. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
23 */ |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 public static final Metrics INSTANCE = |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 new LinearMetrics(); |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 |
805
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
27 /** |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
28 * Implements the corresponding linear interpolator. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
29 */ |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 public static final class LinearInterpolator |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 implements Interpolator |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 { |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 private double mx; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 private double bx; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 private double my; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 private double by; |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 |
805
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
38 /** |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
39 * Constructor to create a linear interpolator between two |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
40 * given points. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
41 * @param p1 The first point. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
42 * @param p2 The second point. |
bb7afd783321
Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
43 */ |
361
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
360
diff
changeset
|
44 public LinearInterpolator(Coordinate p1, Coordinate p2) { |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 /* |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 I) p1.x = 0*m + bx |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 II) p2.x = 1*m + bx |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 bx = p1.x |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 p2.x = m + p1.x |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 mx = p2.x - p1.x |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 */ |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 |
361
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
360
diff
changeset
|
57 bx = p1.x; |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
360
diff
changeset
|
58 mx = p2.x - bx; |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 |
361
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
360
diff
changeset
|
60 by = p1.y; |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
360
diff
changeset
|
61 my = p2.y - by; |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 |
361
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
360
diff
changeset
|
64 public void interpolate(double t, Coordinate v) { |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
360
diff
changeset
|
65 v.x = t*mx + bx; |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
360
diff
changeset
|
66 v.y = t*my + by; |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 } // class LinearInterpolator |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 private LinearMetrics() { |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 |
361
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
360
diff
changeset
|
73 public double distance(Coordinate p1, Coordinate p2) { |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 return p1.distance(p2); |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 |
361
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
360
diff
changeset
|
77 public Interpolator getInterpolator(Coordinate p1, Coordinate p2) { |
360
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 return new LinearInterpolator(p1, p2); |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 } |
ee760729f6b8
Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 } |
836
05bf8534a35a
Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
805
diff
changeset
|
81 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |