Search Unity

No tan/atan/atan2 functions in Mathf class?

Discussion in 'Scripting' started by andeeeee, Jul 19, 2005.

  1. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    The Mathf class has sin, cos, asin and acos methods but doesn't appear to have tan, atan or atan2. Have they been left out deliberately or is this just an oversight? I know you can synthesise them using the other functions and a bit of arithmetic but they are convenient (atan2 is especially useful for converting a position to an angle).

    Or maybe they are in another class and I can't find them?
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    It is an oversight. Will be fixed with 1.1.

    You can use the System.Math.Atan2 for now.
     
    leventseckin likes this.
  3. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    Here's the doc on that, if you're interested:

    http://dotgnu.org/pnetlib-doc/System/Math.html

    Note that most of these are double precision math functions. What that means to you is that you'll have to explicitly typecast back to float... at least in C#

    so at least in C#,

    Code (csharp):
    1. using System;
    2. float myValue = (float)Math.Atan2(0.4, 0.5);
    3.  
    -Jon
     
  4. freyr

    freyr

    Joined:
    Apr 7, 2005
    Posts:
    1,148
    ... and here's how you would do it from js:

    Code (csharp):
    1.  
    2. import System;
    3.  
    4. myValue = Math.Atan2(0.4, 0.5);
    5.  
    6.  
    ... note: no type casting and generally no worrying about types at all. :wink: