/Engine/Source/Runtime/GeometryCore/Public/FrameTypes.h
Compute rotation around NormalAxis that best-aligns one of the other two frame axes with either given UpAxis or FallbackAxis (FallbackAxis is required if Dot(NormalAxis,UpAxis) > UpDotTolerance, ie if the Normal and Up directions are too closely aligned. Basically this divides direction-sphere into three regions - polar caps with size defined by UpDotTolerance, and a wide equator band covering the rest. When crossing between these regions the alignment has a discontinuity. It is impossible to avoid this discontinuity because it is impossible to comb a sphere.
void ConstrainedAlignPerpAxes ( int PerpAxis1, int PerpAxis2, int NormalAxis, const [TVector](API\Runtime\Core\Math\TVector)< RealType > & UpAxis, const [TVector](API\Runtime\Core\Math\TVector)< RealType > & FallbackAxis, RealType UpDotTolerance )