From 4b19dc9ffce638276a546ef17d51442a96377d6b Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Tue, 1 Oct 2019 11:41:18 -0400 Subject: [PATCH] Add TODOs to rotate_angle for a change in azimuth --- src/distribution_multi.cpp | 10 ++++++++-- src/math_functions.cpp | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/distribution_multi.cpp b/src/distribution_multi.cpp index 0c1ecddecb..c388254b6e 100644 --- a/src/distribution_multi.cpp +++ b/src/distribution_multi.cpp @@ -59,8 +59,14 @@ Direction PolarAzimuthal::sample() const double mu = mu_->sample(); if (mu == 1.0) return u_ref_; - // Sample the azimuthal angle with an offset to match azimuth conventions - double phi = phi_->sample() + 0.5*PI; + // Sample azimuthal angle + double phi = phi_->sample(); + + // If the reference direction is along the z-axis, rotate the aziumthal angle + // to match spherical coordinate conventions. + // TODO: apply this change directly to rotate_angle + if (u_ref_.x == 0 && u_ref_.y == 0) phi += 0.5*PI; + return rotate_angle(u_ref_, mu, &phi); } diff --git a/src/math_functions.cpp b/src/math_functions.cpp index ec5d64eac7..7525a7ddda 100644 --- a/src/math_functions.cpp +++ b/src/math_functions.cpp @@ -665,6 +665,12 @@ Direction rotate_angle(Direction u, double mu, const double* phi) return {mu*u.x + a*(u.x*u.y*cosphi + u.z*sinphi) / b, mu*u.y - a*b*cosphi, mu*u.z + a*(u.y*u.z*cosphi - u.x*sinphi) / b}; + // TODO: use the following code to make PolarAzimuthal distributions match + // spherical coordinate conventions. Remove the related fixup code in + // PolarAzimuthal::sample. + //return {mu*u.x + a*(-u.x*u.y*sinphi + u.z*cosphi) / b, + // mu*u.y + a*b*sinphi, + // mu*u.z - a*(u.y*u.z*sinphi + u.x*cosphi) / b}; } }