annotate gnv-artifacts/src/main/java/de/intevation/gnv/math/Point2d.java @ 601:4c6d2b4df3ae

Changes id_layer of Table layerhasparameter from literal to number. gnv-artifacts/trunk@659 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Fri, 05 Feb 2010 10:36:46 +0000
parents b248531fa20b
children c4156275c1e1
rev   line source
361
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.gnv.math;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
593
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
3 import com.vividsolutions.jts.geom.Coordinate;
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
4 import com.vividsolutions.jts.geom.Envelope;
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
5
361
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 import java.util.Comparator;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7
593
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
8 import org.apache.log4j.Logger;
361
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 /**
593
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
11 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de)
361
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 */
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 public class Point2d
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 extends Coordinate
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 {
593
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
16 private static Logger log = Logger.getLogger(Point2d.class);
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
17
365
f66088a43ecc Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 361
diff changeset
18 public static final double EPSILON = 1e-3d;
361
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 public static final Comparator X_COMPARATOR = new Comparator() {
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 public int compare(Object a, Object b) {
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 double xa = ((Coordinate)a).x;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 double xb = ((Coordinate)b).x;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 if (xa < xb) return -1;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 if (xa > xb) return +1;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 return 0;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 }
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 };
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 public static final Comparator Y_COMPARATOR = new Comparator() {
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 public int compare(Object a, Object b) {
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 double ya = ((Coordinate)a).y;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 double yb = ((Coordinate)b).y;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 if (ya < yb) return -1;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 if (ya > yb) return +1;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 return 0;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 }
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 };
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 public static class InverseL1Comparator
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 implements Comparator
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 {
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 private Point2d ref;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 public InverseL1Comparator(Point2d ref) {
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 this.ref = ref;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 }
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 public int compare(Object a, Object b) {
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 Point2d pa = (Point2d)a;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 Point2d pb = (Point2d)b;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 double da = ref.L1(pa);
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 double db = ref.L1(pb);
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 if (da < db) return -1;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 if (da > db) return +1;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 return 0;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 }
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58 } // class InverseL1Comparator
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60 public int i;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61 public int j;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 public Point2d() {
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 }
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65
593
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
66 public Point2d(double x, double y) {
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
67 super(x, y);
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
68 }
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
69
431
422275fc9927 Refactored the XYColumn and Point2d code a bit to be more reusable in 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 365
diff changeset
70 public Point2d(double x, double y, int i, int j) {
422275fc9927 Refactored the XYColumn and Point2d code a bit to be more reusable in 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 365
diff changeset
71 super(x, y);
422275fc9927 Refactored the XYColumn and Point2d code a bit to be more reusable in 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 365
diff changeset
72 this.i = i;
422275fc9927 Refactored the XYColumn and Point2d code a bit to be more reusable in 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 365
diff changeset
73 this.j = j;
422275fc9927 Refactored the XYColumn and Point2d code a bit to be more reusable in 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 365
diff changeset
74 }
422275fc9927 Refactored the XYColumn and Point2d code a bit to be more reusable in 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 365
diff changeset
75
361
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76 public Point2d(double x, double y, double z, int i, int j) {
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77 super(x, y, z);
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78 this.i = i;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79 this.j = j;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
80 }
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
81
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
82
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
83 public double L1(Point2d other) {
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
84 return L1(this, other);
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
85 }
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
86
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87 public static double L1(Coordinate a, Coordinate b) {
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88 return Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89 }
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91 public Envelope envelope() {
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92 return envelope(EPSILON);
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93 }
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95 public Envelope envelope(double epsilon) {
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96 return new Envelope(
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97 x-epsilon, x+epsilon,
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98 y-epsilon, y+epsilon);
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
99 }
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 public boolean hasIGap(Point2d other) {
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102 return Math.abs(i - other.i) > 1;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103 }
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
105 public boolean hasJGap(Point2d other) {
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106 return Math.abs(j - other.j) > 1;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
107 }
593
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
108
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
109 public Point2d extrapolate(double t, Point2d other) {
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
110 if (other == null) {
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
111 return null;
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
112 }
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
113 Point2d p = newPoint();
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
114 p.x = t*(other.x - x) + x;
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
115 p.y = t*(other.y - y) + y;
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
116 return p;
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
117 }
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
118
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
119 public Point2d newPoint() {
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
120 return new Point2d(0d, 0d);
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
121 }
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
122
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
123 public Point2d newPoint(double x, double y) {
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
124 return new Point2d(x, y);
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
125 }
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
126
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
127 public void inverseDistanceWeighting(Point2d [] ps) {
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
128
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
129 double sum = 0d;
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
130
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
131 double [] d = new double[ps.length];
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
132
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
133 for (int i = 0; i < ps.length; ++i) {
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
134 Point2d p = ps[i];
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
135 if (p != null) {
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
136 double di = distance(p);
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
137 if (di < 1e-5d) { z = p.z; return; }
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
138 di = 1d/di;
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
139 d[i] = di;
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
140 sum += di;
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
141 }
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
142 }
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
143
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
144 if (sum == 0d) {
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
145 return;
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
146 }
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
147
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
148 double v = 0d;
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
149
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
150 for (int i = 0; i < ps.length; ++i) {
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
151 Point2d p = ps[i];
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
152 if (p != null) {
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
153 v += p.z*d[i];
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
154 }
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
155 }
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
156 z = v/sum;
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
157 }
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
158
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
159 public static Point2d average(Point2d [] ps) {
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
160
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
161 Point2d p = null;
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
162 int count = 0;
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
163
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
164 for (int i = 0; i < ps.length; ++i) {
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
165 Point2d t = ps[i];
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
166 if (t != null) {
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
167 ++count;
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
168 if (p == null) {
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
169 p = t.newPoint(t.x, t.y);
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
170 }
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
171 else {
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
172 p.x += t.x;
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
173 p.y += t.y;
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
174 }
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
175 }
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
176 }
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
177
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
178 if (p != null) {
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
179 double s = 1d/count;
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
180 p.x *= s;
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
181 p.y *= s;
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
182 }
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
183
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
184 return p;
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
185 }
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
186
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
187 public boolean near(Point2d [] ps) {
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
188
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
189 for (int i = 0; i < ps.length; ++i) {
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
190 Point2d p = ps[i];
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
191 if (p != null && distance(p) > EPSILON) {
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
192 return false;
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
193 }
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
194 }
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
195
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
196 return true;
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
197 }
361
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
198 }
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
199 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org