/// <summary>Calculates the angle between two absolute directions</summary> /// <param name="firstPhi">First absolute direction in radians</param> /// <param name="secondPhi">Second absolute direction in radians</param> /// <param name="path">Path to take from first to second</param> /// <returns>The angle between both directions using the desired path</returns> /// <remarks> /// See the remarks on the TangentialPath enumeration to determine the exact /// behavior of this function. A positive path is always from the first angle /// to the second, independent of whether this is clockwise or counter-clockwise. /// </remarks> public static double AngleBetween(double firstPhi, double secondPhi, TangentialPath path) { double difference = secondPhi - firstPhi; double angle; if (path == TangentialPath.Shortest) { // Just unroll the difference of both angles and we have the angle angle = Shared <UncheckedScalarMath> .Instance.Wrap(difference, 0.0, Perigon); // Calculate angle of shortest path if we got the one of the longest path if (angle >= System.Math.PI) { angle -= Perigon; } } else { // Unroll the difference depending on the sign of the resulting angle if (difference < 0.0) { angle = math.Wrap(difference, -Perigon, 0.0); if (path == TangentialPath.Negative) { angle += Perigon; } } else { angle = math.Wrap(difference, 0.0, Perigon); if (path == TangentialPath.Negative) { angle -= Perigon; } } } return(angle); }
/// <summary>Calculates the angle between two absolute directions</summary> /// <param name="firstPhi">First absolute direction in radians</param> /// <param name="secondPhi">Second absolute direction in radians</param> /// <param name="path">Path to take from first to second</param> /// <returns>The angle between both directions using the desired path</returns> /// <remarks> /// See the remarks on the TangentialPath enumeration to determine the exact /// behavior of this function. A positive path is always from the first angle /// to the second, independent of whether this is clockwise or counter-clockwise. /// </remarks> public static double AngleBetween(double firstPhi, double secondPhi, TangentialPath path) { double difference = secondPhi - firstPhi; double angle; if(path == TangentialPath.Shortest) { // Just unroll the difference of both angles and we have the angle angle = Shared<UncheckedScalarMath>.Instance.Wrap(difference, 0.0, Perigon); // Calculate angle of shortest path if we got the one of the longest path if(angle >= System.Math.PI) angle -= Perigon; } else { // Unroll the difference depending on the sign of the resulting angle if(difference < 0.0) { angle = math.Wrap(difference, -Perigon, 0.0); if(path == TangentialPath.Negative) angle += Perigon; } else { angle = math.Wrap(difference, 0.0, Perigon); if(path == TangentialPath.Negative) angle -= Perigon; } } return angle; }