diff --git a/src/ZrnHe.jl b/src/ZrnHe.jl index 6cf127f..a11112a 100644 --- a/src/ZrnHe.jl +++ b/src/ZrnHe.jl @@ -1,34 +1,34 @@ """ ```julia -intersectionfraction(๐“‡โ‚, ๐“‡โ‚‚, d) +intersectionfraction(rโ‚, rโ‚‚, d) ``` -Calculate the fraction of the surface area of a sphere s2 with radius `๐“‡โ‚‚` -that intersects the interior of a sphere s1 of radius `๐“‡โ‚` if the two are -separated by distance `d`. Assumptions: `๐“‡โ‚`>0, `๐“‡โ‚‚`>0, `d`>=0 +Calculate the fraction of the surface area of a sphere s2 with radius `rโ‚‚` +that intersects the interior of a sphere s1 of radius `rโ‚` if the two are +separated by distance `d`. Assumptions: `rโ‚`>0, `rโ‚‚`>0, `d`>=0 """ -function intersectionfraction(๐“‡โ‚::T, ๐“‡โ‚‚::T, d::T) where T <: Number - dmax = ๐“‡โ‚+๐“‡โ‚‚ - dmin = abs(๐“‡โ‚-๐“‡โ‚‚) +function intersectionfraction(rโ‚::T, rโ‚‚::T, d::T) where T <: Number + dmax = rโ‚+rโ‚‚ + dmin = abs(rโ‚-rโ‚‚) if d > dmax ## If separated by more than dmax, there is no intersection omega = zero(T) elseif d > dmin # X is the radial distance between the center of s2 and the interseciton plane # See e.g., http://mathworld.wolfram.com/Sphere-SphereIntersection.html - # x = (d^2 - ๐“‡โ‚^2 + ๐“‡โ‚‚^2) / (2 * d) + # x = (d^2 - rโ‚^2 + rโ‚‚^2) / (2 * d) # Let omega be is the solid angle of intersection normalized by 4pi, # where the solid angle of a cone is 2pi*(1-cos(theta)) and cos(theta) - # is adjacent/hypotenuse = x/๐“‡โ‚‚. - # omega = (1 - x/๐“‡โ‚‚)/2 + # is adjacent/hypotenuse = x/rโ‚‚. + # omega = (1 - x/rโ‚‚)/2 # Rearranged for optimization: - omega = one(T)/2 - (d^2 - ๐“‡โ‚^2 + ๐“‡โ‚‚^2) / (4 * d * ๐“‡โ‚‚) + omega = one(T)/2 - (d^2 - rโ‚^2 + rโ‚‚^2) / (4 * d * rโ‚‚) - elseif ๐“‡โ‚<๐“‡โ‚‚ # If ๐“‡โ‚ is entirely within ๐“‡โ‚‚ + elseif rโ‚