comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/geom/Lines.java @ 2673:0143b44631cc

Beginnings of mittlere hoehe calculation. flys-artifacts/trunk@4367 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 09 May 2012 19:03:54 +0000
parents 9d2a06c3a134
children 2be59d5b342c
comparison
equal deleted inserted replaced
2672:5afccab9aac1 2673:0143b44631cc
24 24
25 public static enum Mode { UNDEF, WET, DRY }; 25 public static enum Mode { UNDEF, WET, DRY };
26 26
27 protected Lines() { 27 protected Lines() {
28 } 28 }
29
30
31 /**
32 * Calculate area of polygon with four vertices.
33 * @return area of polygon with four vertices.
34 */
35 public static double area(Point2D p1, Point2D p2, Point2D p3, Point2D p4) {
36 double[] x = new double[] {p1.getX(), p2.getX(), p3.getX(), p4.getX() };
37 double[] y = new double[] {p1.getY(), p2.getY(), p3.getY(), p4.getY() };
38 double area = 0d;
39 int j = 3;
40 for (int i=0; i <4; i++) {
41 area += (x[j] + x[i]) * (y[j] - y[i]);
42 j = i;
43 }
44 return area * 0.5d;
45 }
46
29 47
30 /** 48 /**
31 * Calculate the 'length' of the given lines. 49 * Calculate the 'length' of the given lines.
32 */ 50 */
33 public static double length(List<Line2D> lines) { 51 public static double length(List<Line2D> lines) {
57 return result; 75 return result;
58 } 76 }
59 77
60 if (N == 1) { 78 if (N == 1) {
61 Point2D p = points.get(0); 79 Point2D p = points.get(0);
62 // Only generate point if over water 80 // Only generate point if over profile
63 if (waterLevel > p.getY()) { 81 if (waterLevel > p.getY()) {
64 result.add(new Line2D.Double( 82 result.add(new Line2D.Double(
65 p.getX(), waterLevel, 83 p.getX(), waterLevel,
66 p.getX(), waterLevel)); 84 p.getX(), waterLevel));
67 } 85 }
92 log.debug("complete under water"); 110 log.debug("complete under water");
93 result.add(new Line2D.Double(minX, waterLevel, maxX, waterLevel)); 111 result.add(new Line2D.Double(minX, waterLevel, maxX, waterLevel));
94 return result; 112 return result;
95 } 113 }
96 114
115 // Water is sometimes above, sometimes under profile.
97 Mode mode = Mode.UNDEF; 116 Mode mode = Mode.UNDEF;
98 117
99 double startX = minX; 118 double startX = minX;
100 119
120 double area = 0d;
121 // Walking along the profile.
101 for (int i = 1; i < N; ++i) { 122 for (int i = 1; i < N; ++i) {
102 Point2D p1 = points.get(i-1); 123 Point2D p1 = points.get(i-1);
103 Point2D p2 = points.get(i); 124 Point2D p2 = points.get(i);
104 125
105 if (p1.getY() < waterLevel && p2.getY() < waterLevel) { 126 if (p1.getY() < waterLevel && p2.getY() < waterLevel) {
109 } 130 }
110 if (mode != Mode.WET) { 131 if (mode != Mode.WET) {
111 startX = p1.getX(); 132 startX = p1.getX();
112 mode = Mode.WET; 133 mode = Mode.WET;
113 } 134 }
135 area += area(p1, p2,
136 new Point2D.Double(p2.getX(), waterLevel),
137 new Point2D.Double(p1.getX(), waterLevel));
114 continue; 138 continue;
115 } 139 }
116 140
141 // TODO trigger area calculation
117 if (p1.getY() > waterLevel && p2.getY() > waterLevel) { 142 if (p1.getY() > waterLevel && p2.getY() > waterLevel) {
118 if (debug) { 143 if (debug) {
119 log.debug("over water: " + p1 + " " + p2); 144 log.debug("over water: " + p1 + " " + p2);
120 } 145 }
121 // completely over water 146 // completely over water
127 } 152 }
128 mode = Mode.DRY; 153 mode = Mode.DRY;
129 continue; 154 continue;
130 } 155 }
131 156
157 // TODO trigger area calculation
132 if (Math.abs(p1.getX() - p2.getX()) < EPSILON) { 158 if (Math.abs(p1.getX() - p2.getX()) < EPSILON) {
133 // vertical line 159 // vertical line
134 switch (mode) { 160 switch (mode) {
135 case WET: 161 case WET:
136 log.debug("vertical/wet"); 162 log.debug("vertical/wet");
160 // check if waterlevel directly hits the vertices; 186 // check if waterlevel directly hits the vertices;
161 187
162 boolean p1W = Math.abs(waterLevel - p1.getY()) < EPSILON; 188 boolean p1W = Math.abs(waterLevel - p1.getY()) < EPSILON;
163 boolean p2W = Math.abs(waterLevel - p2.getY()) < EPSILON; 189 boolean p2W = Math.abs(waterLevel - p2.getY()) < EPSILON;
164 190
191 // TODO trigger area calculation
165 if (p1W || p2W) { 192 if (p1W || p2W) {
166 if (debug) { 193 if (debug) {
167 log.debug("water hits vertex: " + p1 + " " + p2 + " " + mode); 194 log.debug("water hits vertex: " + p1 + " " + p2 + " " + mode);
168 } 195 }
169 if (p1W && p2W) { // parallel to water -> dry 196 if (p1W && p2W) { // parallel to water -> dry
213 log.debug("mode is now: " + mode); 240 log.debug("mode is now: " + mode);
214 } 241 }
215 continue; 242 continue;
216 } 243 }
217 244
245 // TODO trigger area calculation
218 // intersection case 246 // intersection case
219 double x = Linear.linear( 247 double x = Linear.linear(
220 waterLevel, 248 waterLevel,
221 p1.getY(), p2.getY(), 249 p1.getY(), p2.getY(),
222 p1.getX(), p2.getX()); 250 p1.getX(), p2.getX());
272 * Class holding points that form lines and the calculated length. 300 * Class holding points that form lines and the calculated length.
273 */ 301 */
274 public static class LineData { 302 public static class LineData {
275 public double [][] points; 303 public double [][] points;
276 public double width; 304 public double width;
277 public LineData(double[][] points, double width) { 305 public double area;
306 public LineData(double[][] points, double width, double area) {
278 this.points = points; 307 this.points = points;
279 this.width = width; 308 this.width = width;
309 this.area = area;
280 } 310 }
281 } 311 }
282 312
283 313
284 public static LineData createWaterLines( 314 public static LineData createWaterLines(
311 } 341 }
312 } 342 }
313 343
314 return new LineData( 344 return new LineData(
315 new double [][] { lxs.toNativeArray(), lys.toNativeArray() }, 345 new double [][] { lxs.toNativeArray(), lys.toNativeArray() },
316 linesLength 346 linesLength, 0d
317 ); 347 );
318 } 348 }
319 } 349 }
320 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 350 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org