Skip to contents

Computes the normalized solid angle of a two-dimensional simplicial cone generated by two vectors using the signed area (atan2) variant of the planar angle formula. The result is the fraction of the unit circle covered by the cone.

Usage

solid_angle_2d(v1, v2)

Arguments

v1

Numeric vector of length two; first cone generator. Need not be unit-normalized.

v2

Numeric vector of length two; second cone generator.

Value

A single numeric value in \([0, 0.5]\): the planar opening angle divided by \(2\pi\). Colinear generators (including opposite rays) return 0.

Details

For two unit vectors \(v_1, v_2 \in \mathbb{R}^2\) the planar opening angle in \([0, \pi]\) is $$\theta = \mathrm{atan2}(|\det[v_1\ v_2]|,\ v_1 \cdot v_2),$$ and the normalized solid angle is \(\Omega = \theta / (2\pi)\). The atan2-based form is numerically stable for nearly orthogonal as well as nearly colinear inputs, where the dot-product/acos form loses precision near \(\pm 1\).

Inputs are normalized to unit norm internally. The dot product is clamped to \([-1, 1]\) to guard against floating-point overshoot. Generators detected as colinear (signed area below \(10^{-12}\) and absolute dot product within \(10^{-12}\) of unity) define a lower-dimensional cone and return 0.

References

Beyer, W. H. (1987). CRC Standard Mathematical Tables, 28th edition. CRC Press. ISBN 0-8493-0628-0.

See also

solid_angle_2d_inner for the dot-product/acos variant; solid_angle_3d for the three-dimensional analogue; compute_solid_angle for the dispatcher that uses this formula automatically when \(n = 2\).

Examples

# Right angle (quarter plane)
solid_angle_2d(c(1, 0), c(0, 1))           # 0.25
#> [1] 0.25

# 45-degree opening
solid_angle_2d(c(1, 0), c(1, 1) / sqrt(2)) # 0.125
#> [1] 0.125

# Opposite rays: degenerate planar cone
solid_angle_2d(c(1, 0), c(-1, 0))          # 0
#> [1] 0