Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/geom/Lines.java @ 2688:99350b06a780
Improved middle height calculations.
flys-artifacts/trunk@4389 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 11 May 2012 08:45:11 +0000 |
parents | dc67ddd4a34c |
children | ed07dd55f487 |
comparison
equal
deleted
inserted
replaced
2687:dc67ddd4a34c | 2688:99350b06a780 |
---|---|
33 /** | 33 /** |
34 * Calculate area of polygon with four vertices. | 34 * Calculate area of polygon with four vertices. |
35 * @return area of polygon with four vertices. | 35 * @return area of polygon with four vertices. |
36 */ | 36 */ |
37 public static double area(Point2D p1, Point2D p2, Point2D p3, Point2D p4) { | 37 public static double area(Point2D p1, Point2D p2, Point2D p3, Point2D p4) { |
38 double[] x = new double[] {p1.getX(), p2.getX(), p3.getX(), p4.getX() }; | 38 double[] x = new double[] {p1.getX(), p2.getX(), p3.getX(), p4.getX(), p1.getX() }; |
39 double[] y = new double[] {p1.getY(), p2.getY(), p3.getY(), p4.getY() }; | 39 double[] y = new double[] {p1.getY(), p2.getY(), p3.getY(), p4.getY(), p1.getY() }; |
40 double area = 0d; | 40 double area = 0d; |
41 int j = 3; | |
42 for (int i=0; i <4; i++) { | 41 for (int i=0; i <4; i++) { |
43 area += (x[j] + x[i]) * (y[j] - y[i]); | 42 area += (x[i] * y[i+1]) - (x[i+1] * y[i]); |
44 j = i; | 43 } |
45 } | 44 return Math.abs(area * 0.5d); |
46 return area * 0.5d; | |
47 } | 45 } |
48 | 46 |
49 | 47 |
50 /** | 48 /** |
51 * Calculate the 'length' of the given lines. | 49 * Calculate the 'length' of the given lines. |