Coverage for pyguymer3/geo/_area.py: 100%
8 statements
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-08 18:47 +0000
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-08 18:47 +0000
1#!/usr/bin/env python3
3# Define function ...
4def _area(
5 triangle,
6 /,
7 *,
8 eps = 1.0e-12,
9 nIter = 100,
10):
11 """Find the area of a triangle.
13 Parameters
14 ----------
15 triangle : shapely.geometry.polygon.Polygon
16 the triangle
17 eps : float, optional
18 the tolerance of the Vincenty formula iterations
19 nIter : int, optional
20 the maximum number of iterations (particularly the Vincenty formula)
22 Returns
23 -------
24 area : float
25 the area (in metres-squared)
27 Notes
28 -----
29 Copyright 2017 Thomas Guymer [1]_
31 References
32 ----------
33 .. [1] PyGuymer3, https://github.com/Guymer/PyGuymer3
34 """
36 # Import standard modules ...
37 import math
39 # Import sub-functions ...
40 from .calc_dist_between_two_locs import calc_dist_between_two_locs
42 # Check inputs ...
43 assert len(triangle.exterior.coords) == 4, "\"triangle\" is not a triangle"
45 # **************************************************************************
47 # Find the distance from the second point to the first point, and the
48 # bearing of the first point as viewed from the second point ...
49 a, bearing1, _ = calc_dist_between_two_locs(
50 triangle.exterior.coords[1][0],
51 triangle.exterior.coords[1][1],
52 triangle.exterior.coords[0][0],
53 triangle.exterior.coords[0][1],
54 eps = eps,
55 nIter = nIter,
56 ) # [m], [°]
58 # Find the distance from the second point to the third point, and the
59 # bearing of the third point as viewed from the second point ...
60 b, bearing2, _ = calc_dist_between_two_locs(
61 triangle.exterior.coords[1][0],
62 triangle.exterior.coords[1][1],
63 triangle.exterior.coords[2][0],
64 triangle.exterior.coords[2][1],
65 eps = eps,
66 nIter = nIter,
67 ) # [m], [°]
69 # Use the two bearings to find the interior angle between the first and
70 # third points ...
71 C = (bearing2 - bearing1) % 180.0 # [°]
73 # Return answer ...
74 return 0.5 * a * b * math.sin(math.radians(C))