I'm trying to do something that should be very simple, find the difference between two angles. Possible values are 0 - TwoPi, I'm getting stumped when I have something like 0.1 and 6.18 - I know this should only take a couple of lines but every time I come up with a solution its way, way too long/slow. C# btw...
>>5
If you want it to wrap 2pi, untested and could be buggy. private double diff(double first, double second) {
double ans = Math.abs(first%(2*Math.Pi)-second%(2*Math.Pi))
return ans > Math.Pi ? diff(first+Math.Pi, second+Math.Pi) : ans;
}
Rank: VIPPER | Subject: Re: Our dark secrets
Registered: |
2005-03-04 | What you want to do is convert the angle
Posts: 2358 | into degrees, do the arithmetic mod 360,
| then convert back into radians
/l、 |
(゚、 。 7 |
l、 ~ヽ |_________________________________________________________________________
じしf_, )ノ | ``Computer science is the black magic of the 20th century'' -- A.C. Cudders
Name:
Anonymous2009-06-13 3:33
Rank: VIPPER | Subject: Re: C# difference in angles
Registered: |
2005-03-04 | What you want to do is convert the angle
Posts: 2358 | into degrees, do the arithmetic mod 360,
| then convert back into radians
/l、 |
(゚、 。 7 |
l、 ~ヽ |_________________________________________________________________________
じしf_, )ノ | ``Computer science is the black magic of the 20th century'' -- A.C. Cudders