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.

source
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.

source
CoarseGrainingEnergyFluxes.Geometry.ball_box_fraction — Method
ball_box_fraction(x1, x2, y1, y2, z1, z2, r, nodes) -> T

The 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.

source
CoarseGrainingEnergyFluxes.Geometry.cap_cell_fraction — Method
cap_cell_fraction(λa, λb, φa, φb, β, θ, nodes) -> T

The 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.

source
CoarseGrainingEnergyFluxes.Geometry.cap_half_width — Method
cap_half_width(φ, β, θ) -> T

The 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 β, Δ = φ − β, Σ = φ + β.

source
CoarseGrainingEnergyFluxes.Geometry.cap_polygon_fraction — Method
cap_polygon_fraction(V, θ) -> T

The 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.

source
CoarseGrainingEnergyFluxes.Geometry.disk_fraction — Method
disk_fraction(x_min::Real, x_max::Real, y_min::Real, y_max::Real, r::Real) -> AbstractFloat

Analytic 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.

source
CoarseGrainingEnergyFluxes.Geometry.disk_fraction — Method
disk_fraction(Lx::Real, Ly::Real, r::Real) -> AbstractFloat

Analytic 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).

source
CoarseGrainingEnergyFluxes.Geometry.disk_fraction — Method
disk_fraction(poly::AbstractVector{NTuple{2,T}}, r::Real) where {T<:AbstractFloat} -> T

Compute 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).

source
CoarseGrainingEnergyFluxes.Geometry.geodesic_cell_fraction — Method
geodesic_cell_fraction(d, λa, λb, φa, φb, nodes) -> T

The 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).

source
CoarseGrainingEnergyFluxes.Geometry.geodesic_disk — Method
geodesic_disk(direct, metric, R, t, whole) -> GeodesicDisk

The 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.

source
CoarseGrainingEnergyFluxes.Geometry.geodetic_cell_fraction — Method
geodetic_cell_fraction(ball, λa, λb, φa, φb, ha, hb, nodes) -> T

The 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.

source
CoarseGrainingEnergyFluxes.Geometry.geodetic_layer — Method
geodetic_layer(ball, h) -> GeodeticLayer

The 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₀²)ρ′.

source
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)).

source
CoarseGrainingEnergyFluxes.Geometry.quadrant_disk_area2 — Method
quadrant_disk_area2(X::T, Y::T, r::T, r²::T) where {T<:AbstractFloat} -> T

Compute 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).

source
CoarseGrainingEnergyFluxes.Geometry.shell_cell_fraction — Method
shell_cell_fraction(λa, λb, φa, φb, ra, rb, β, r0, R, nodes) -> T

The 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.

source