185 | | center = new EastNorth(0, 0); |
186 | | Node n0 = (Node) nodes.toArray()[nodes.size() - 1]; |
187 | | Node n1 = (Node) nodes.toArray()[nodes.size() - 2]; |
188 | | Node n2; |
189 | | for (Node n : nodes) { |
190 | | n2 = n1; |
191 | | n1 = n0; |
192 | | n0 = n; |
193 | | EastNorth cc = circumcenter(n0.getEastNorth(), n1.getEastNorth(), n2.getEastNorth()); |
194 | | if (cc == null) |
195 | | return; |
196 | | center = new EastNorth(center.east() + cc.east(), center.north() |
197 | | + cc.north()); |
| 185 | |
| 186 | // Compute the centroid of nodes |
| 187 | |
| 188 | // See http://en.wikipedia.org/w/index.php?title=Centroid&oldid=294224857#Centroid_of_polygon for the equation used here |
| 189 | double area = 0; |
| 190 | double north = 0; |
| 191 | double east = 0; |
| 192 | |
| 193 | // Integrate the area, east and north centroid, we'll compute the final value based on the result of integration |
| 194 | for (int i=0; i<nodes.size(); i++) { |
| 195 | EastNorth n0 = ((Node) nodes.toArray()[i]).getEastNorth(); |
| 196 | EastNorth n1 = ((Node) nodes.toArray()[(i+1) % nodes.size()]).getEastNorth(); |
| 197 | |
| 198 | area += n0.east()*n1.north()-n1.east()*n0.north(); |
| 199 | east += (n0.east() +n1.east()) *(n0.east()*n1.north()-n1.east()*n0.north()); |
| 200 | north += (n0.north()+n1.north())*(n0.east()*n1.north()-n1.east()*n0.north()); |