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

Pages: 1-

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:03

I don't know why but I thought this would work...


public float Anglediff(float a1, float a2)
{
   a1 = Math.Abs(MathHelper.WrapAngle(a1 + MathHelper.Pi - a2) - MathHelper.Pi);
return a1;
}

it doesn't...

Name: Anonymous 2009-06-13 1:05

private double calculateDifferenceBetweenAngles(double firstAngle, double secondAngle)
  {
        double difference = secondAngle - firstAngle;
        while (difference < -180) difference += 360;
        while (difference > 180) difference -= 360;
        return difference;
 }

Name: Anonymous 2009-06-13 1:20

hmm that doesn't seem to always work...

Name: Anonymous 2009-06-13 1:23

private double diff(double first, double second) {
    return Math.abs(first%(2*Math.Pi)-second%(2*Math.Pi));
}

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

Name: Anonymous 2009-06-13 1:32


        private double AngleDifference(double angle0, double angle1)
        {
            return Math.Abs((angle0 + 180 - angle1) % 360 - 180);
        }

Name: Anonymous 2009-06-13 1:40

>>6
that one works great, thank you so much :)

Name: Anonymous 2009-06-13 2:13

why dont youj ust use haskell

Name: Anonymous 2009-06-13 2:28

>>9
Improper capitalization, no punctuation and spaces in the wrong place
Is this the current state of the Haskell community?

Name: Anonymous 2009-06-13 2:50

>>10
y dun u jsy us haskl

Name: Anonymous 2009-06-13 2:54

>>11
*jst

Name: Anonymous 2009-06-13 3:00

>>10
faggy improper french capitalization
is this the current state of pedantry?

Name: Anonymous 2009-06-13 3:20

Name: Anonymous 2009-06-13 3:32

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: Anonymous 2009-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

Name: Anonymous 2009-06-13 4:16

diff = a2 - a1;

Name: Anonymous 2010-11-14 21:53

Name: Anonymous 2010-11-15 4:51

Name: Anonymous 2011-02-04 15:46

Name: marco polo 2011-04-28 16:04

this work.

       public static double GetPositiveAngle(double radian)
        {
            if (radian < 0)
                radian = (Math.PI * 2) - Math.Abs(radian);

            return radian;
        }

        private static double GetAngleDifference(double angle1, double angle2)
        {
            var rslt1 = GetPositiveAngle(angle1);
            var rslt2 = GetPositiveAngle(angle2);

            if (rslt2 < rslt1)
                rslt2 += 2 * Math.PI;

            return rslt2 - rslt1;
        }

Name: Anonymous 2011-04-28 17:29


VICTORY TO THE FARTISTS!

Name: Anonymous 2011-04-28 17:34


VICTORY TO THE FARTISTS!

Name: Anonymous 2011-04-28 17:35


VICTORY TO THE FARTISTS!

Name: Anonymous 2011-04-28 19:20


VICTORY TO THE FARTISTS!

Name: Anonymous 2011-04-28 19:33

But whom will save Xarn?

Name: Anonymous 2011-04-30 6:20

Name: Anonymous 2013-08-31 18:19



What's everyone's favorite computer from the era of 8-bit computers? What were your favorite parts about it? Share your thoughts, feelings, and facts on the 8-bit computers of the late 70's and 80's.

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