Cell geometry
CoarseGrainingEnergyFluxes.Geometry.GeodesicDisk — Type
GeodesicDisk{T,M,N}The disk of geodesic radius R about latitude t, longitude 0, on a surface of revolution whose lengths per unit latitude and longitude are metric(φ) = (M, N cos φ): its latitude span where w > 0, the latitudes open = (A, B) between which 0 < w < π and w at them (ends: 0, or π across a covered pole), the latitude turn of w's one extreme between them (an end where w is monotone), whole where it holds every point, and the N-term Chebyshev series on [A, B] of h = sin²(w/2) cos φ and of its first two derivatives in the series' variable.
CoarseGrainingEnergyFluxes.Geometry.GeodeticBall — Type
GeodeticBall{T}The ball of radius R about the point at latitude t, longitude 0, height h0 above a spheroid of equatorial radius a and squared eccentricity e2, at (Xc, 0, Zc).
CoarseGrainingEnergyFluxes.Geometry.GeodeticLayer — Type
GeodeticLayer{T}The ball ball at height h: the region |λ| ≤ w(φ) with its latitude span, open, ends, turn and whole as a GeodesicDisk's.
CoarseGrainingEnergyFluxes.Geometry._region_overlap — Method
_region_overlap(r, λa, λb, φa, φb, nodes) -> (inside, whole)∫ density·L dφ over [φa, φb], L the longitudes of [λa, λb] (relative to the region's centre, at most 2π wide) inside the region r; whole where every point of the cell is inside, the overlap then the cell's own, and 0 exactly where every point is outside. Summed between the latitudes where L changes form (the region's span, where it holds a whole circle, where its edge crosses a face meridian), each piece by the Gauss–Legendre nodes = (x, w) on [−1, 1] under a smoothstep substitution.
CoarseGrainingEnergyFluxes.Geometry.ball_box_fraction — Method
ball_box_fraction(x1, x2, y1, y2, z1, z2, r, nodes) -> TThe fraction of the box [x1, x2] × [y1, y2] × [z1, z2] inside the origin-centred ball of radius r: the integral over z of each slice's rectangle ∩ disk of radius √(r² − z²) (disk_fraction), by the Gauss–Legendre nodes = (x, w) on the pieces between the heights where that radius passes an edge line's distance (its foot on the edge) or a corner's, each under a smoothstep substitution. 1 and 0 exactly for a box wholly inside or outside.
CoarseGrainingEnergyFluxes.Geometry.cap_arc_fraction — Method
cap_arc_fraction(λa, λb, φ, β, θ) -> TThe fraction of the arc [λa, λb] of the circle of latitude φ inside the cap of angular radius θ about latitude β, longitude 0: a cell of a grid with one latitude.
CoarseGrainingEnergyFluxes.Geometry.cap_cell_fraction — Method
cap_cell_fraction(λa, λb, φa, φb, β, θ, nodes) -> TThe fraction of the latitude–longitude cell [λa, λb] × [φa, φb] inside the spherical cap of angular radius θ about latitude β, longitude 0: longitudes relative to the cap's centre, 0 < λb − λa ≤ 2π, latitudes in [−π/2, π/2], φa < φb. 1 or 0 exactly when every point of the cell is inside or outside. Otherwise the overlap ∫ cos φ L(φ) dφ, L the cell's longitudes within cap_half_width, summed between the latitudes where L changes form (the cap's extreme latitudes, where it holds a whole circle, and where its boundary crosses a face meridian), each piece by the Gauss–Legendre nodes = (x, w) on [−1, 1] under a smoothstep substitution.
CoarseGrainingEnergyFluxes.Geometry.cap_half_width — Method
cap_half_width(φ, β, θ) -> TThe half-width in longitude of the spherical cap of angular radius θ about latitude β, longitude 0, on the circle of latitude φ: the cap holds (λ, φ) for |λ| ≤ w, w = 0 where the circle misses it and w = π where it holds the whole circle. From hav d = hav(φ − β) + cos φ cos β hav λ, sin²(w/2) and cos²(w/2) are sin((θ − Δ)/2) sin((θ + Δ)/2) and sin((π − Σ − θ)/2) sin((π − Σ + θ)/2) over their common factor cos φ cos β, Δ = φ − β, Σ = φ + β.
CoarseGrainingEnergyFluxes.Geometry.cap_polygon_fraction — Method
cap_polygon_fraction(V, θ) -> TThe fraction of the spherical polygon whose great-circle edges join the unit vectors V in turn inside the cap of angular radius θ about (0, 0, 1); the polygon spans less than a hemisphere. 1 exactly when every vertex is inside. A polygon centred on the far hemisphere is one less its fraction inside the complementary cap about (0, 0, −1), so the point the formula is singular at never lies inside the polygon.
CoarseGrainingEnergyFluxes.Geometry.disk_fraction — Method
disk_fraction(x_min::Real, x_max::Real, y_min::Real, y_max::Real, r::Real) -> AbstractFloatAnalytic fast path for the fraction of an axis-aligned rectangle [x_min, x_max] × [y_min, y_max] (or 3D rectangular prism [x_min, x_max] × [y_min, y_max] × [z_min, z_max]) that overlaps with an origin-centered disk/cylinder of radius r.
CoarseGrainingEnergyFluxes.Geometry.disk_fraction — Method
disk_fraction(Lx::Real, Ly::Real, r::Real) -> AbstractFloatAnalytic fast path for the fraction of an origin-centered rectangle (or rectangular prism with horizontal footprint [-Lx/2, Lx/2] × [-Ly/2, Ly/2]) that lies within a cylinder/disk of radius r centered at (0, 0).
CoarseGrainingEnergyFluxes.Geometry.disk_fraction — Method
disk_fraction(poly::AbstractVector{NTuple{2,T}}, r::Real) where {T<:AbstractFloat} -> TCompute the fraction in [0, 1] of a simple 2D polygon's area that lies within a disk of radius r centered at the origin (0, 0).
CoarseGrainingEnergyFluxes.Geometry.edge_disk_area2 — Method
edge_disk_area2(ax, ay, bx, by, cross_ab, r²)Compute twice the signed area swept from the origin (0, 0) to the directed line segment a -> b clipped to a disk of squared radius r².
CoarseGrainingEnergyFluxes.Geometry.geodesic_arc_fraction — Method
geodesic_arc_fraction(d, λa, λb) -> TThe fraction of the arc [λa, λb] of the circle of latitude through the centre of d inside it: a cell of a grid with one latitude.
CoarseGrainingEnergyFluxes.Geometry.geodesic_cell_fraction — Method
geodesic_cell_fraction(d, λa, λb, φa, φb, nodes) -> TThe fraction of the latitude–longitude cell [λa, λb] × [φa, φb] inside the geodesic disk d: longitudes relative to its centre, 0 < λb − λa ≤ 2π, latitudes in [−π/2, π/2], φa < φb. 1 or 0 exactly when every point of the cell is inside or outside; otherwise ∫ M N cos φ L(φ) dφ over the cell's area (_region_overlap).
CoarseGrainingEnergyFluxes.Geometry.geodesic_disk — Method
geodesic_disk(direct, metric, R, t, whole) -> GeodesicDiskThe disk of geodesic radius R about latitude t, longitude 0: direct(α) returns the point (λ, φ) at distance R along the azimuth α (east of north), its longitude the one swept, so ±π past a pole, and R lies short of every cut locus; metric(φ) the lengths (M, N cos φ) per unit latitude and longitude; whole where the disk holds every point. h is interpolated through N edge points, barycentrically, and re-expanded at the Chebyshev points of [A, B]; the latitude of w's extreme is the root of (h/cos φ)′, from the sphere's.
CoarseGrainingEnergyFluxes.Geometry.geodesic_disk_area — Method
geodesic_disk_area(d, nodes) -> TThe area of the disk d, 2 ∫ M N cos φ w(φ) dφ over its span.
CoarseGrainingEnergyFluxes.Geometry.geodesic_half_width — Method
geodesic_half_width(d, φ) -> TThe half-width w in longitude of the disk d on the circle of latitude φ: 0 where it misses the circle, π where it holds it.
CoarseGrainingEnergyFluxes.Geometry.geodesic_meridian_fraction — Method
geodesic_meridian_fraction(d, φa, φb, nodes) -> TThe fraction of the meridian segment [φa, φb] through the centre of d inside it, by length: a cell of a grid with one longitude.
CoarseGrainingEnergyFluxes.Geometry.geodesic_meridian_length — Method
geodesic_meridian_length(d, nodes) -> TThe length of the meridian through the centre of d inside it, ∫ M dφ over its span.
CoarseGrainingEnergyFluxes.Geometry.geodetic_cell_fraction — Method
geodetic_cell_fraction(ball, λa, λb, φa, φb, ha, hb, nodes) -> TThe fraction of the geodetic cell [λa, λb] × [φa, φb] × [ha, hb] inside ball: longitudes relative to its centre's, 0 < λb − λa ≤ 2π. 1 exactly where every corner and every point of its latitude faces at longitude π lies inside; otherwise ∫ A(h) dh over the cell's volume, A(h) the overlap of its layer at height h (_region_overlap, weighted by (M + h)(N + h) cos φ), summed between the heights where the ball's surface crosses the normal through a corner, a latitude face's point at longitude 0 or π, a pole, or a meridian face's point nearest the centre, and h₀ ± R, by the Gauss–Legendre nodes under a smoothstep substitution.
CoarseGrainingEnergyFluxes.Geometry.geodetic_layer — Method
geodetic_layer(ball, h) -> GeodeticLayerThe ball at height h. Along the centre's meridian D₀ is least, |h − h₀|, at t (the constant-height surfaces share their normals, the centre on the one at t), so the span's ends are the roots of D₀ = R on each side; a pole inside the ball is covered, and the circle there ends where the opposite meridian leaves the ball. w's extreme is the root of u′ ∝ −(D₀²)′ρ − (R² − D₀²)ρ′.
CoarseGrainingEnergyFluxes.Geometry.interval_fraction — Method
interval_fraction(a, b, r) -> TThe fraction of the segment [a, b] (a < b) inside [-r, r].
CoarseGrainingEnergyFluxes.Geometry.meridian_crossings — Method
meridian_crossings(λ, β, θ) -> (s₁, s₂)Where the boundary of the cap of angular radius θ about latitude β, longitude 0, meets the great circle through the meridian of longitude λ, as angles along that circle from its equator crossing at λ, north positive; an angle in [−π/2, π/2] is a latitude on the meridian itself. NaNs where they do not meet. The circle passes δ from the centre, sin δ = cos β |sin λ|, nearest it at s* = atan(sin β, cos β cos λ), and meets the boundary at s* ± η, tan²(η/2) = sin((θ−δ)/2) sin((θ+δ)/2) / (cos((θ−δ)/2) cos((θ+δ)/2)).
CoarseGrainingEnergyFluxes.Geometry.quadrant_disk_area2 — Method
quadrant_disk_area2(X::T, Y::T, r::T, r²::T) where {T<:AbstractFloat} -> TCompute twice the exact area of the intersection between the first-quadrant rectangle [0, X] × [0, Y] (with X >= 0, Y >= 0) and the origin-centered disk of radius r (r² = r^2).
CoarseGrainingEnergyFluxes.Geometry.sector_area2 — Method
sector_area2(px, py, qx, qy, r²)Compute twice the signed area of the circular sector of radius r (given as squared radius r²) swept from ray p = (px, py) to ray q = (qx, qy) around the origin (0, 0).
CoarseGrainingEnergyFluxes.Geometry.shell_cell_fraction — Method
shell_cell_fraction(λa, λb, φa, φb, ra, rb, β, r0, R, nodes) -> TThe fraction of the spherical shell sector [λa, λb] × [φa, φb] × [ra, rb] inside the ball of radius R about the point at latitude β, longitude 0, radius r0: longitudes relative to that point's, latitudes in [−π/2, π/2], radii 0 ≤ ra < rb. On the sphere of radius r the ball is the cap of angular radius θ(r), sin²(θ/2) = (R − (r − r0))(R + (r − r0)) / (4 r r0), so the fraction is ∫ r² f(θ(r)) dr / ((rb³ − ra³)/3) with f the cell's fraction in that cap (cap_cell_fraction), by the Gauss–Legendre nodes on the pieces between the radii where θ(r) reaches 0 or π or passes an angle where f changes form, graded toward each. 1 and 0 exactly for a sector wholly inside or outside.
CoarseGrainingEnergyFluxes.Geometry.signed_quadrant_disk_area2 — Method
signed_quadrant_disk_area2(x::T, y::T, r::T, r²::T) where {T<:AbstractFloat} -> TSigned version of quadrant_disk_area2 for arbitrary coordinates (x, y) in any quadrant: returns sign(x) * sign(y) * quadrant_disk_area2(abs(x), abs(y), r, r²).