什么是Quaternion四元数

1843年,William Rowan Hamilton发明了四元数,但直到1985年才有一个叫Ken Shoemake的人将四元数引入计算机图形学处理领域。四元数在3D图形学中主要用于旋转,骨骼动画等。

简单地来说,四元数描述了一次旋转:绕任意一个轴(V)旋转一个弧度(θ)。

那么四元数q就与(V,θ)两个参数有关。

具体公式:

q = (sin(θ / 2) * V,cos(θ / 2) )

q = (sin(θ / 2) * x,sin(θ / 2) * y,sin(θ / 2) * z,cos(θ / 2))

在Unity中使用Quaternion对象

创建Quaternion对象

//
float radians = 90 / 360f * Mathf.PI * 2;
//
Vector3 n = Vector3.up; //
float w = Mathf.Cos (radians / 2);
//
float s = Mathf.Sin (radians / 2); //
float x = n.x * s;
float y = n.y * s;
float z = n.z * s; //
transform.rotation = new Quaternion (x, y, z, w);

上述代码,可以设置一个游戏对象沿着Y轴向上的方向顺时针旋转90度

Quaternion对象的方法

实例方法

Set用法

//
float radians = degress / 360f * Mathf.PI * 2;
//
Vector3 n = Vector3.up; //
float w = Mathf.Cos (radians / 2);
//
float s = Mathf.Sin (radians / 2); //
float x = n.x * s;
float y = n.y * s;
float z = n.z * s; //
Quaternion q = new Quaternion ();
q.Set (x, y, z, w); //
transform.rotation = q;

SetFromRatation用法

//
Quaternion q = new Quaternion ();
q.SetFromToRotation (Vector3.up, Vector3.left); //
transform.rotation = q;

SetLookRotation用法

//
Quaternion q = new Quaternion ();
q.SetLookRotation (Vector3.back); //
transform.rotation = q;

静态方法

//
transform.rotation = Quaternion.identity; //
transform.rotation = Quaternion.AngleAxis (degress, Vector3.up); //
transform.rotation = Quaternion.Dot (q1, q2); //
transform.rotation = Quaternion.Inverse (q1); //
transform.rotation = Quaternion.Lerp(q1,q2,Time.deltaTime); //
transform.rotation = Quaternion.Slerp (q1, q2, Time.deltaTime);

[Unity Quaternion]四元数Quaternion的计算方式的更多相关文章

  1. 【转】【Unity】四元数(Quaternion)和旋转

    http://blog.csdn.net/candycat1992/article/details/41254799

  2. 学习和研究下unity3d的四元数 Quaternion

    学习和研究下unity3d的四元数 Quaternion 今天准备学习和研究下unity3d的四元数 Quaternion 四元数在电脑图形学中用于表示物体的旋转,在unity中由x,y,z,w 表示 ...

  3. unity3d的四元数 Quaternion

    原地址:http://www.cnblogs.com/88999660/archive/2013/04/02/2995074.html 今天准备学习和研究下unity3d的四元数 Quaternion ...

  4. Quaternion 四元数

    Quaternions are used to represent rotations. 四元数用于表示旋转. They are compact, don't suffer from gimbal l ...

  5. 四元数Quaternion的基本运算

    技术背景 在前面一篇文章中我们介绍了欧拉角死锁问题的一些产生背景,还有基于四元数的求解方案.四元数这个概念虽然重要,但是很少会在通识教育课程中涉及到,更多的是一些图形学或者是工程学当中才会进行讲解.本 ...

  6. Unity3D_(API)Quaternion四元数中的Quaternion.LookRotation()

    四元数百度百科: 传送门 四元数官方文档: 传送门 欧拉旋转.四元数.矩阵旋转之间的差异: 传送门 四元数转换为欧拉角eulerAngles 官方文档: 传送门 欧拉角转换为四元数Euler 官方文档 ...

  7. System.currentTimeMillis()计算方式与时间的单位转换

    目录[-] 一.时间的单位转换 二.System.currentTimeMillis()计算方式 一.时间的单位转换 1秒=1000毫秒(ms) 1毫秒=1/1,000秒(s)1秒=1,000,000 ...

  8. NTC(负温度)热敏电阻.阻值的计算方式

    来源 :http://blog.csdn.net/blue0432/article/details/8690190 现在低成本测温方案中NTC热敏电阻用的比较多,一般采用查表的方法获取温度值,这就牵涉 ...

  9. mysql中TPS, QPS 的计算方式

    今天突然有个同事问题一个问题, mysqlTPS和QPS的计算公式是什么? 以前确实也没有关注过这个计算公式,所以查了下学习了下: 下面是参考内容.  在做db基准测试的时候,qps,tps 是衡量数 ...

随机推荐

  1. cssText笔记

    style.cssText 用来获取/设置元素的样式 设置: <div id= "a" style= "background: red;"> doc ...

  2. 【转】Java 内部类种类及使用解析

    Java 内部类种类及使用解析 内部类Inner Class 将相关的类组织在一起,从而降低了命名空间的混乱. 一个内部类可以定义在另一个类里,可以定义在函数里,甚至可以作为一个表达式的一部分. Ja ...

  3. 命令行编译swc

    compc -source-path . -include-classes com.boyaa.landlo rd.module.room.RoomMain -output a.swc -compil ...

  4. HDU - 1083 Courses /POJ - 1469

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1083 http://poj.org/problem?id=1469 题意:给你P个课程,并且给出每个课 ...

  5. windbg 之 如何设置模块加载时断下

    这里先介绍两个指令: sx指令: The sx* commands control the action that the debugger takes when an exception occur ...

  6. 凹凸曼的修改zencart 程序(经典!)

    ==================================================================================================== ...

  7. P2P应用中的NAT穿透问题

    多年前曾经写过一个关于NAT钻洞的实验.现在发现那个做法在我现在的路由器上已经不管用了.经过一番搜索发现时过境迁,世界变化很快,新路由器已经是UPnP了.在这里重新理一下几种方法. 第一种,也是不太靠 ...

  8. Mysql 随机查询数据

    SELECT * FROM tablename ORDER BY RAND() LIMIT 10

  9. opencv-jni -调试出错taking address of temporary [-fpermissive]

    今天在进行代码往安卓平台移植时,IplImage *qImg=&(IplImage)dst1;报错taking address of temporary [-fpermissive] 百度了一 ...

  10. HDU 2546 饭卡 01背包变形

    题目大意:中文题就不多说了 题目思路:由题意可知,只要高于5元,就可以随便刷,那我们就把最贵的留在最后刷.但是如果低于5元就什么也不能刷(哪怕你要买的物品价格不足五元),所以我们可以先求出(n-5)元 ...