none
Is C# working with degrees or radians? RRS feed

  • Question

  • When you use the Math library the Sin, Cos, ACos, etc methods work with radians but in graphics.DrawArc the startAngle and sweepAngle must be given in degrees.

    It's not a big problem but it's a bit confusing to have to go passing between radians an degrees all the time.

     

    PS Sorry, I know I have to improve my English

    Sunday, July 2, 2006 10:20 PM

Answers

  • C# doesn't use either. The C# language has no built-in notion of angles. And since it doesn't have any native representation of an angle, it doesn't actually make sense to ask whether it works with degrees or radians.

    Math.Cos, Math.Tan and so on are not part of C#. They are part of the .NET Framework Base Class Library. As such, they are language-neutral - the same functions are available to VB.NET, Python, Ruby, and any other language available for the .NET framework.

    Likewise, Graphics.DrawArc is also part of the .NET Framework class libraries. (Technically speaking, I don't think they're part of the Base Class Library. The ECMA CLI specification defines the BCL as being a fairly small subset of the .NET Framework. So the System.Math class is in the FCL and the BCL, but System.Drawing.Graphics is only in the FCL. But I'm being pedantic...)

    So I'll rephrase your question for you if you don't mind:

    Do the .NET Framework Class Libraries work with degrees or radians?

    And the answer is...both!

    The methods in the System.Math class use radians. The types in System.Drawing (GDI+) seem to use degrees.

    In short, the .NET Framework isn't terribly consistent here.

    Monday, July 3, 2006 7:56 AM

All replies

  • Convert from radians to degrees with
      double degrees = radians * 180 / Math.PI

    Sunday, July 2, 2006 10:33 PM
    Moderator
  • Those methods are documented as working with radians.
    Monday, July 3, 2006 2:27 AM
    Moderator
  • DrawArc seems to need degrees though...

    Monday, July 3, 2006 6:35 AM
    Moderator
  • C# doesn't use either. The C# language has no built-in notion of angles. And since it doesn't have any native representation of an angle, it doesn't actually make sense to ask whether it works with degrees or radians.

    Math.Cos, Math.Tan and so on are not part of C#. They are part of the .NET Framework Base Class Library. As such, they are language-neutral - the same functions are available to VB.NET, Python, Ruby, and any other language available for the .NET framework.

    Likewise, Graphics.DrawArc is also part of the .NET Framework class libraries. (Technically speaking, I don't think they're part of the Base Class Library. The ECMA CLI specification defines the BCL as being a fairly small subset of the .NET Framework. So the System.Math class is in the FCL and the BCL, but System.Drawing.Graphics is only in the FCL. But I'm being pedantic...)

    So I'll rephrase your question for you if you don't mind:

    Do the .NET Framework Class Libraries work with degrees or radians?

    And the answer is...both!

    The methods in the System.Math class use radians. The types in System.Drawing (GDI+) seem to use degrees.

    In short, the .NET Framework isn't terribly consistent here.

    Monday, July 3, 2006 7:56 AM
  • IanG said:

    C# doesn't use either. The C# language has no built-in notion of angles. And since it doesn't have any native representation of an angle, it doesn't actually make sense to ask whether it works with degrees or radians.

    Math.Cos, Math.Tan and so on are not part of C#. They are part of the .NET Framework Base Class Library. As such, they are language-neutral - the same functions are available to VB.NET, Python, Ruby, and any other language available for the .NET framework.

    Likewise, Graphics.DrawArc is also part of the .NET Framework class libraries. (Technically speaking, I don't think they're part of the Base Class Library. The ECMA CLI specification defines the BCL as being a fairly small subset of the .NET Framework. So the System.Math class is in the FCL and the BCL, but System.Drawing.Graphics is only in the FCL. But I'm being pedantic...)

    So I'll rephrase your question for you if you don't mind:

    Do the .NET Framework Class Libraries work with degrees or radians?

    And the answer is...both!

    The methods in the System.Math class use radians. The types in System.Drawing (GDI+) seem to use degrees.

    In short, the .NET Framework isn't terribly consistent here.



    C# doesnt use either?

    Then why did you say:

    "The methods in the system.math class use radians"

    if they dont use either? how can it use radians?

    and why the answer "they use both" later in the post.  

    I know its dated post but it was marked as answer and its a bit confusing and id like to understand the logic, if it is logical.
    Friday, September 19, 2008 1:18 PM
  • He's making a distinction between C# and the .Net Framework Class Libraries (FCL), and indicating that it's the specific methods of the library classes of the framework that use either degrees or radians, and not the C# language itself. By itself (meaning w/o the Framework Class Libraries) C# does not implement those trigonometric functions (e.g. Sin, Cos, etc).

    Friday, January 4, 2013 4:39 AM