comparison gnv-artifacts/src/main/java/de/intevation/gnv/math/LinearMetrics.java @ 360:ee760729f6b8

Added mapping from linear diagram space to 2D map coordinates. gnv-artifacts/trunk@434 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 15 Dec 2009 15:58:58 +0000
parents
children aec85d00d82c
comparison
equal deleted inserted replaced
359:59ad8f37a590 360:ee760729f6b8
1 package de.intevation.gnv.math;
2
3 import java.awt.geom.Point2D;
4
5 import de.intevation.gnv.math.LinearToMap.Metrics;
6 import de.intevation.gnv.math.LinearToMap.Interpolator;
7
8 /**
9 * @author Sascha L. Teichmann
10 */
11 public final class LinearMetrics
12 implements Metrics
13 {
14 public static final Metrics INSTANCE =
15 new LinearMetrics();
16
17 public static final class LinearInterpolator
18 implements Interpolator
19 {
20 private double mx;
21 private double bx;
22 private double my;
23 private double by;
24
25 public LinearInterpolator(Point2D p1, Point2D p2) {
26
27 /*
28 I) p1.x = 0*m + bx
29 II) p2.x = 1*m + bx
30
31 bx = p1.x
32
33 p2.x = m + p1.x
34
35 mx = p2.x - p1.x
36 */
37
38 bx = p1.getX();
39 mx = p2.getX() - bx;
40
41 by = p1.getY();
42 my = p2.getY() - by;
43 }
44
45 public void interpolate(double t, Point2D v) {
46 double x = t*mx + bx;
47 double y = t*my + by;
48 v.setLocation(x, y);
49 }
50 } // class LinearInterpolator
51
52 private LinearMetrics() {
53 }
54
55 public double distance(Point2D p1, Point2D p2) {
56 return p1.distance(p2);
57 }
58
59 public Interpolator getInterpolator(Point2D p1, Point2D p2) {
60 return new LinearInterpolator(p1, p2);
61 }
62 }
63 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org