문제

I need to make an efficient function that matches this footprint:

public static double NearestAngle(this double currentAngle, double targetAngle);

where the return value is targetAngle +/- n*2pi. The return value should minimize the absolute difference between itself and currentAngle. How can I do this efficiently in C#? I want to avoid loops as the inputs can be many circles apart.

도움이 되었습니까?

해결책

return targetAngle + Math.Round((currentAngle - targetAngle)/(2*Math.Pi))*2*Math.Pi;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top