Search Unity

Quaternion.AxisAngle not the same as quaternion.ToAngleAxis()??

Discussion in 'Scripting' started by dreamerflyer, Feb 28, 2020.

  1. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    Confused with this,why?(0.1, 0.0, 0.8, 0.6) and (-0.1, 0.0, -1.0, -0.1)?why not the same?
    Code (CSharp):
    1.   Vector3 localRoll;
    2.         float angle;
    3.         Quaternion quaternion = transform.localRotation;
    4.         // Quaternion  quaternion = new Quaternion();
    5.         quaternion.ToAngleAxis(out angle, out localRoll);
    6.  
    7.         // Debug.Log("start euler:"+obj.localEulerAngles);
    8.         // Debug.Log(localRoll);
    9.         Debug.Log(Quaternion.AxisAngle(localRoll, angle) + " " + quaternion);//out put is (0.1, 0.0, 0.8, 0.6)  (-0.1, 0.0, -1.0, -0.1)
    10.        
     
  2. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,113
    Quaternion.AxisAngle was made obsolete a while ago, because it used radians, which non-math-inclined people find daunting. Use Quaternion.AngleAxis instead.

    I agree that changes like this have made the Quaternion even more confusing than it already was.

    They should've made a different Quaternion struct that operates exclusively with degrees, and make them implicitly cast between each other when needed. Or at least a separate set of extensions methods operating on the same object type.
     
  3. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,113
    anyway, your test should give you the same result if you do
    Code (csharp):
    1. quaternion.ToAngleAxis(out angle, out localRoll);
    2. Debug.Log(Quaternion.AxisAngle(localRoll, angle * Mathf.Deg2Rad);
     
    dreamerflyer likes this.
  4. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    confused with this,they should the same rule to use,also degree or also radians
     
  5. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,113
    It's an older version that was left in only because some people's programs rely on it.
    But you're not supposed to use it now that it is known to be obsolete, because at some point in the future, it might be removed entirely.

    That's what 'obsolete' means in programming terms.
     
    dreamerflyer likes this.