Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Anyone got a library for radian based functions?

Discussion in 'Scripting' started by Nanako, Nov 19, 2014.

  1. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    hi, it seems that a lot of unity's built in functions take degrees as input and do stuff with them. but i believe this involves an extra conversion step, especially where rotation math is concerned. functions that can take radians as input directly would be more effective, no?

    i figure by now someone must have rewritten all the degree-input functions into versions that take radians. Anyone got such a code library that i could use? maybe a static class with static functions
     
  2. Kirk Clawson

    Kirk Clawson

    Joined:
    Nov 4, 2014
    Posts:
    65
    if you're using C#, all of the basic .net Math functions (System.Math.cos() for example) use radians. Other than that, if you're not afraid of source code, there's always https://github.com/mathnet
    You'll be primarily interested in mathnet-spatial. But if you go down that road, you'll have to evaluate which is the cheaper conversion? Your code converting Unity Vectors/Matrices to your library's Vectors/Matrices, or Unity doing the deg2rad conversion?
     
  3. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    It's only really Vector3.Angle, a couple of angular velocity things, and a few Quaternion functions that deal in degrees, and it doesn't make great sense to be dealing with quats in radians.
    All of the Mathf trig functions are in radians
     
  4. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,377
    I have a few methods in my VectorUtil that can take radians.

    https://code.google.com/p/spacepupp...owse/trunk/SpacepuppyBase/Utils/VectorUtil.cs

    I haven't gone through and written any radian versions of existing functions. Though I wouldn't mind doing it.

    You will notice though that I default to degrees in my VectorUtil. This is because despite my preferring radians to do math, I display everything as degrees in the editor for the benefit of the designer.

    NOTE - the unity methods that take degrees just do an extra multiplication step, and that's it. The overhead isn't that intense.

    Tell you what though... if you go out and seek down all the functions that take degrees and would benefit from radians, organize it into a list with name, inputs, and output. I'll write the implementations for them. I have no problem writing the code, I just don't want to hunt down all the functions.