Search Unity

ToAngleAxis(), angularVelocity - Degrees or Radians?

Discussion in 'Editor & General Support' started by Zergling103, Mar 20, 2014.

  1. Zergling103

    Zergling103

    Joined:
    Aug 16, 2011
    Posts:
    392
    Some unity classes like Quaternion and Configurable joint have some properties that are described as "angles" - such as Quaternion.ToAngleAxis() returning an angle-axis representation of the quaternion, or Rigidbody having "angularVelocity", or a configurable joint having a "targetAngularVelocity".

    For all of these items, and perhaps others, it is not documented anywhere whether these values are measured in degrees or radians. I'd think whether degrees or radians are used isn't a trivial detail.

    From some quick tests, it appears that degrees and radians are used interchangeably, at random. Quaternion.Angle() returns a result in degrees (it is documented as such) whereas Quaternion.ToAngleAxis() -seems to- use radians. Vector3, Quaternion, and Mathf all deal with angles at some point and I still haven't figured out the pattern as to where degrees or radians are used. AFAIK, everything in Mathf uses radians.

    I'd like this forum post to be a reference for future developers who encounter this problem. (And yes, I've searched for a similar post with not much luck.)

    The members listed below use Degrees as their unit for measuring angles:

    Quaternion.ToAngleAxis()
    CharacterJoint.highTwistLimit
    CharacterJoint.lowTwistLimit
    CharacterJoint.swing1Limit
    CharacterJoint.swing2Limit
    ConfigurableJoint.highAngularXLimit
    ConfigurableJoint.lowAngularXLimit
    ConfigurableJoint.angularYLimit
    ConfigurableJoint.angularZLimit

    The following angular velocities are measured in Radians per Second:

    ConfigurableJoint.targetAngularVelocity
    Physics.maxAngularVelocity
    Physics.sleepAngularVelocity
    Rigidbody.angularVelocity
    Rigidbody.maxAngularVelocity
    Rigidbody.sleepAngularVelocity

    I have not yet determined the units used for these properties:

    ConfigurableJoint.projectionAngle- presumably Degrees

    Below I've listed Gotchas related to radians or degrees being used:

    Quaternion.RotateTowards()
    uses degrees for the maximum angular delta, whereas Vector3.RotateTowards() uses radians.
    HingeJoint.velocity is measured in degrees per second, whereas all other joints use radians per second.
     
    Last edited: Mar 20, 2014
    JohnAustinPontoco and tamberlain like this.