Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C# difference in angles

Name: Anonymous 2009-06-13 1:01

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...

halp?

Name: Anonymous 2009-06-13 1:31

>>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;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List