Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/math/LinearMetrics.java @ 875:5e9efdda6894
merged gnv-artifacts/1.0
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:13:56 +0200 |
parents | 05bf8534a35a |
children | f953c9a559d8 |
comparison
equal
deleted
inserted
replaced
722:bb3ffe7d719e | 875:5e9efdda6894 |
---|---|
1 package de.intevation.gnv.math; | |
2 | |
3 import com.vividsolutions.jts.geom.Coordinate; | |
4 | |
5 /** | |
6 * Implements {@link de.intevation.gnv.math.Metrics} | |
7 * for linear interpolations and distance measurements. | |
8 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> | |
9 */ | |
10 public final class LinearMetrics | |
11 implements Metrics | |
12 { | |
13 /** | |
14 * Instance to prevent needless creations of instances. | |
15 */ | |
16 public static final Metrics INSTANCE = | |
17 new LinearMetrics(); | |
18 | |
19 /** | |
20 * Implements the corresponding linear interpolator. | |
21 */ | |
22 public static final class LinearInterpolator | |
23 implements Interpolator | |
24 { | |
25 private double mx; | |
26 private double bx; | |
27 private double my; | |
28 private double by; | |
29 | |
30 /** | |
31 * Constructor to create a linear interpolator between two | |
32 * given points. | |
33 * @param p1 The first point. | |
34 * @param p2 The second point. | |
35 */ | |
36 public LinearInterpolator(Coordinate p1, Coordinate p2) { | |
37 | |
38 /* | |
39 I) p1.x = 0*m + bx | |
40 II) p2.x = 1*m + bx | |
41 | |
42 bx = p1.x | |
43 | |
44 p2.x = m + p1.x | |
45 | |
46 mx = p2.x - p1.x | |
47 */ | |
48 | |
49 bx = p1.x; | |
50 mx = p2.x - bx; | |
51 | |
52 by = p1.y; | |
53 my = p2.y - by; | |
54 } | |
55 | |
56 public void interpolate(double t, Coordinate v) { | |
57 v.x = t*mx + bx; | |
58 v.y = t*my + by; | |
59 } | |
60 } // class LinearInterpolator | |
61 | |
62 private LinearMetrics() { | |
63 } | |
64 | |
65 public double distance(Coordinate p1, Coordinate p2) { | |
66 return p1.distance(p2); | |
67 } | |
68 | |
69 public Interpolator getInterpolator(Coordinate p1, Coordinate p2) { | |
70 return new LinearInterpolator(p1, p2); | |
71 } | |
72 } | |
73 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |