Package com.irurueta.navigation.geodesic
Class PolygonArea
java.lang.Object
com.irurueta.navigation.geodesic.PolygonArea
Polygon areas.
This computes the area of a geodesic polygon using the method given Section 6 of
- C. F. F. Karney, Algorithms for geodesics, J. Geodesy 87, 43–55 (2013)
// Compute the area of a geodesic polygon.
// This program reads lines with lat, lon for each vertex of a polygon.
// At the end of input, the program prints the number of vertices,
// the perimeter of the polygon and its area (for the WGS84 ellipsoid).
import java.util.*;
import com.irurueta.navigation.geodesic.*;
public class Planimeter {
public static void main(String[] args) {
PolygonArea p = new PolygonArea(Geodesic.WGS84, false);
try {
Scanner in = new Scanner(System.in);
while (true) {
double lat = in.nextDouble(), lon = in.nextDouble();
p.AddPoint(lat, lon);
}
}
catch (Exception e) {}
PolygonResult r = p.Compute();
System.out.println(r.num + " " + r.perimeter + " " + r.area);
}
}
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final double
private Accumulator
private int
private final Geodesic
private double
private double
private double
private double
private final int
private int
private final Accumulator
private final boolean
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addEdge
(double azi, double s) Add an edge to the polygon or polyline.void
addPoint
(double lat, double lon) Add a point to the polygon or polyline.void
clear()
Clear PolygonArea, allowing a new polygon to be started.compute()
Return the results so far.compute
(boolean reverse, boolean sign) Return the results so far.Report the previous vertex added to the polygon or polyline.double
Gets the flattening of the ellipsoid.double
Gets the equatorial radius of the ellipsoid (meters).testEdge
(double azi, double s, boolean reverse, boolean sign) Return the results assuming a tentative final test point is added via an azimuth and distance; however, the data for the test point is not saved.testPoint
(double lat, double lon, boolean reverse, boolean sign) Return the results assuming a tentative final test point is added; however, the data for the test point is not saved.private static int
transit
(double lon1, double lon2) private static int
transitDirect
(double lon1, double lon2)
-
Field Details
-
earth
-
area0
private final double area0 -
polyline
private final boolean polyline -
mask
private final int mask -
num
private int num -
crossings
private int crossings -
areasum
-
perimetersum
-
lat0
private double lat0 -
lon0
private double lon0 -
lat1
private double lat1 -
lon1
private double lon1
-
-
Constructor Details
-
Method Details
-
clear
public void clear()Clear PolygonArea, allowing a new polygon to be started. -
addPoint
public void addPoint(double lat, double lon) Add a point to the polygon or polyline. lat should be in the range [−90°, 90°].- Parameters:
lat
- the latitude of the point (degrees).lon
- the latitude of the point (degrees).
-
addEdge
public void addEdge(double azi, double s) Add an edge to the polygon or polyline. This does nothing if no points have been added yet. Use PolygonArea.getCurrentPoint to determine the position of the new vertex.- Parameters:
azi
- azimuth at current point (degrees).s
- distance from current point to next point (meters).
-
compute
Return the results so far. Counter-clockwise traversal counts as a positive area.- Returns:
- PolygonResult(num, perimeter, area) where num is the number of vertices, perimeter is the perimeter of the polygon or the length of the polyline (meters), and area is the area of the polygon (meters2) or Double.NaN of polyline is true in the constructor.
-
compute
Return the results so far. More points can be added to the polygon after this call.- Parameters:
reverse
- if true then clockwise (instead of counter-clockwise) traversal counts as a positive area.sign
- if true then return a signed result for the area if the polygon is traversed in the "wrong" direction instead of returning the area for the rest of the earth.- Returns:
- PolygonResult(num, perimeter, area) where num is the number of vertices, perimeter is the perimeter of the polygon or the length of the polyline (meters), and area is the area of the polygon (meters2) or Double.NaN of polyline is true in the constructor.
-
testPoint
Return the results assuming a tentative final test point is added; however, the data for the test point is not saved. This lets you report a running result for the perimeter and area as the user moves the mouse cursor. Ordinary floating point arithmetic is used to accumulate the data for the test point; thus the area and perimeter returned are less accurate than if addPoint and compute are used. lat should be in the range [−90°, 90°].- Parameters:
lat
- the latitude of the test point (degrees).lon
- the longitude of the test point (degrees).reverse
- if true then clockwise (instead of counter-clockwise) traversal counts as a positive area.sign
- if true then return a signed result for the area if the polygon is traversed in the "wrong" direction instead of returning the area for the rest of the earth.- Returns:
- PolygonResult(num, perimeter, area) where num is the number of vertices, perimeter is the perimeter of the polygon or the length of the polyline (meters), and area is the area of the polygon (meters2) or Double.NaN of polyline is true in the constructor.
-
testEdge
Return the results assuming a tentative final test point is added via an azimuth and distance; however, the data for the test point is not saved. This lets you report a running result for the perimeter and area as the user moves the mouse cursor. Ordinary floating point arithmetic is used to accumulate the data for the test point; thus the area and perimeter returned are less accurate than if addPoint and compute are used.- Parameters:
azi
- azimuth at current point (degrees).s
- distance from current point to final test point (meters).reverse
- if true then clockwise (instead of counter-clockwise) traversal counts as a positive area.sign
- if true then return a signed result for the area if the polygon is traversed in the "wrong" direction instead of returning the area for the rest of the earth.- Returns:
- PolygonResult(num, perimeter, area) where num is the number of vertices, perimeter is the perimeter of the polygon or the length of the polyline (meters), and area is the area of the polygon (meters2) or Double.NaN of polyline is true in the constructor.
-
getMajorRadius
public double getMajorRadius()Gets the equatorial radius of the ellipsoid (meters).- Returns:
- a the equatorial radius of the ellipsoid (meters). This is the value inherited from the Geodesic object used in the constructor.
-
getFlattening
public double getFlattening()Gets the flattening of the ellipsoid.- Returns:
- f the flattening of the ellipsoid. This is the value inherited from the Geodesic object used in the constructor.
-
getCurrentPoint
Report the previous vertex added to the polygon or polyline. If no points have been added, then Double.NaN is returned. Otherwise, lon will be in the range [−180°, 180°].- Returns:
- Pair(lat, lon), the current latitude and longitude.
-
transit
private static int transit(double lon1, double lon2) -
transitDirect
private static int transitDirect(double lon1, double lon2)
-