annotate gnv-artifacts/src/main/java/de/intevation/gnv/math/LinearMetrics.java @ 1113:e7efbded1367

Summarized changes for RELEASE 1.1 gnv-artifacts/trunk@1251 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 30 Jun 2010 12:26:04 +0000
parents 05bf8534a35a
children f953c9a559d8
rev   line source
360
ee760729f6b8 Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 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
2
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
3 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
4
ee760729f6b8 Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 /**
805
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
6 * 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
7 * 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
8 * @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
9 */
ee760729f6b8 Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 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
11 implements Metrics
ee760729f6b8 Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 {
805
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
13 /**
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
14 * 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
15 */
360
ee760729f6b8 Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16 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
17 new LinearMetrics();
ee760729f6b8 Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18
805
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
19 /**
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
20 * Implements the corresponding linear interpolator.
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
21 */
360
ee760729f6b8 Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 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
23 implements Interpolator
ee760729f6b8 Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 {
ee760729f6b8 Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 private double mx;
ee760729f6b8 Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 private double bx;
ee760729f6b8 Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 private double my;
ee760729f6b8 Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 private double by;
ee760729f6b8 Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29
805
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
30 /**
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
31 * 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
32 * given points.
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
33 * @param p1 The first point.
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
34 * @param p2 The second point.
bb7afd783321 Removed trailing whitespace. Added more javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
35 */
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
36 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
37
ee760729f6b8 Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 /*
ee760729f6b8 Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 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
40 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
41
ee760729f6b8 Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 bx = p1.x
ee760729f6b8 Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43
ee760729f6b8 Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 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
45
ee760729f6b8 Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 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
47 */
ee760729f6b8 Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48
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
49 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
50 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
51
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
52 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
53 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
54 }
ee760729f6b8 Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55
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
56 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
57 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
58 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
59 }
ee760729f6b8 Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60 } // class LinearInterpolator
ee760729f6b8 Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61
ee760729f6b8 Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 private LinearMetrics() {
ee760729f6b8 Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 }
ee760729f6b8 Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64
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
65 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
66 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
67 }
ee760729f6b8 Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68
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
69 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
70 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
71 }
ee760729f6b8 Added mapping from linear diagram space to 2D map coordinates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72 }
836
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 805
diff changeset
73 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org