当前位置:   article > 正文

四元数的逆

四元数的逆

两个物体在场景中,最初没有设置旋转。

 

 

 

以上两个物体初始没有旋转。

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class Inverse : MonoBehaviour
  5. {
  6. public GameObject goOrg;
  7. public GameObject goNew;
  8. // Start is called before the first frame update
  9. void Start()
  10. {
  11. // 两个物体初始施加同样的旋转、绕Y轴旋转30度。
  12. Quaternion rot1 = Quaternion.AngleAxis(30.0f, Vector3.up);
  13. goOrg.transform.rotation = rot1;
  14. goNew.transform.rotation = rot1;
  15. // New物体的旋转设置为旋转的逆
  16. goNew.transform.rotation = Quaternion.Inverse(rot1);
  17. Debug.Log("Org rotation:");
  18. Debug.Log(goOrg.transform.rotation);
  19. Debug.Log("New rotation:");
  20. Debug.Log(goNew.transform.rotation);
  21. // 使旋转轴变为负Y,结果是一样的
  22. Quaternion rot2 = Quaternion.AngleAxis(30.0f, -Vector3.up);
  23. Debug.Log("Verify rotation:");
  24. Debug.Log(rot2);
  25. }
  26. // Update is called once per frame
  27. void Update()
  28. {
  29. }
  30. }

 结果为红色的(new物体)变为绕Y轴转负30度。原理:四元数取逆就是x, y, z分量取负,此例旋转轴变为负Y。

 

 

 

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/415986
推荐阅读
相关标签
  

闽ICP备14008679号