3D数学之四元组应用及实现

[DirectX12学习笔记] 四元组 四元组 这篇文章内容将比较偏数学,为方便快速复习,这里只列出关键的结论。 四元组简介 四元组类似于一个复数,有实部和虚部,只不过四元组的虚部是个矢量,因此总共有四维,一般来说我们把矢量放在前面,也就是说存在XMFLOAT4里面的时候,前三维是虚部,最后一维是实部。 运算的定义 乘法可以写成矩阵形式 注意因为涉及叉乘,左手系和右手系里的四元组不一样。 乘法和矩阵乘法一样,有结合律没有交换律。 ... 阅读详情

第一次接触四元组是在使用OGRE引擎的时候,那个时候非常好奇,为什么4个数字就能表示一个旋转,另外为什么要用四元组来表示旋转,用旋转矩阵不是挺好的吗?经过一段的时间的学习,算是对四元组有了基础的认识,下面跟大家一起走进神奇的四元组之旅。



四元组,英文名字,Quaternion

先说明下,为什么我们要用四元组

1.它能节省存储空间

2.它的连接(concatenation)运算需要的运算量较少

3.四元组容易插值产生平滑的动画


四元组<w,x,y,z>又被称为4D中的复数,它等价于表达式w+xi+yj+zk,如果让v代表向量<x,y,z>,s代表标量w,那么四元组也可以简写为<s;v>;

其中i,j,k有如下关系:


Two quaternions are defined to be equal if and only if they have exactly the same four
components. (Two unequal quaternions may still represent the same rotation.)


四元组被定义为相等只有当它的四部分都相等时才相等,不能说代表相同的旋转四元组就相等,因为不同的四元组可能代表相同的旋转比如四元组q和-q(为什么?后面会解释)


Addition of quaternions is defined component-wise, namely
(w + xi + yj + zk) + (w' + x'i + y' j + z'k) = (w + w') + (x + x')i+(y + y') j + (z + z')k.

The product of a scalar and quaternion is defined also as expected, namely,
α(w + xi + yj + zk) = (αw) + (αx)i + (αy) j + (αz)k,where α ∈ R.

The product of two quaternions q1 and q2 is denoted q1q2 (we reserve the dot product notation q1 · q2 for the usual dot product).

所以(<s_1;v_1>)(<s_2;v_2>)=s_1s_2-v_1·v_2+s_1v_2+s_2v_1+v_1×v_2

其中标量部分是s_1s_2-v_1·v_2

向量部分是s_1v_2+s_2v_1+v_1×v_2   (由于编辑器的问题不能打出上标和下标,用^代替上标,用_代替下标)


Quaternion addition is commutative and associative.

四元组加法满足交换律和结合律

Quaternion multiplication is associative.The left and right distributive laws hold for quaternions, that is, for all
quaternions q, r, s,q(r + s) = qr + qs and (r + s)q = rq + sq.

四元组乘法满足结合律和交换律


可以通过简单的运算验证上面两个命题

由于向量叉乘不满足交换律,所以四元组乘法也不满足交换律


The norm, or magnitude, of a quaternion q = <w, x, y, z> is defined to equal


||q|| =sqrt(w^2 + x^2 + y^2 + z^2)

We define the conjugate, q*, of q to equal q* = <w,−x,−y,−z>

if q=<s;v>,then ||q||=sqrt(s^2+v^2),where v^2=v·v.Also,q*=<s;-v>

容易验证qq*=q*q=<s^2+v^2;0>=||q||^2


A unit quaternion is a quaternion with norm equal to 1.

A quaternion <w; 0> with zero vector component will be identified with the scalar w ∈ R.
This is compatible with the earlier definitions since the product wq is the same whether w is
interpreted as a quaternion or as a scalar. Similarly, a vector v ∈ R3 will be identified with
the quaternion <0; v> with zero scalar component. 


Care should be taken when vectors are interpreted as quaternions because a vector cross product is not the same as a quaternion product. 

(Indeed, they could not be the same, for quaternion products are associative whereas vector cross products are not.) 

As an example, we have
(i + j) × j = k,
but,
(i + j ) j = (<0, 1, 1, 0>)(<0, 0, 1, 0>) = <−1, 0, 0, 1> ≠< 0, 0, 0, 1> = k.


注意:如果q=<s;v>是一个单位四元组,那他的逆可以很容易计算得到


Fix a unit vector u and a rotation angle θ. Recall that Rθ,u is the rotation around axis u through angle θ
with the rotation direction given by the right-hand rule. 

Let c = cos(θ/2) and s = sin(θ/2),and let q be the quaternion





                                                                   

用任何非0标量a乘以四元组q,并不影响qvq^(-1)的值,也就是说并影响qvq^(-1)对应的旋转.

q与-q可以看作q乘以标量-1,所以用它们来表示旋转(即通过qvq^(-1)来表示旋转)是一样的.

In abstract algebra, a mapping of the form
v → qvq^(−1) 

computed by multiplying on the left by a fixed element and on the right by its inverse is called
an inner automorphism.(内自同构)



We now prove Theorem XII.3.




  




这就证明了假设有四元组q< cos(θ/2) ;sin(θ/2)u>(其中u是单位向量),那么对于向量v,表达式qvq^(-1)得到的结果就是v绕定轴u按右手法则旋转θ度.


Quaternions provide a method of representing rotations by 4-tuples.

 An arbitrary, rigid, orientation-preserving linear transformation can
be expressed as a rotation around some fixed axis. Such a rotation is specified by a rotation
angle θ and a rotation axis u, where u is a unit vector: recall that this rotation was denoted
Rθ,u. To represent Rθ,u with a quaternion, let c = cos(θ/2), s = sin(θ/2), and u = <u_1, u_2, u_3>.
Then the 4-tuple q defined by
q = <c, su_1, su_2, su_3> is called a quaternion

 qVq^(-1)就代表了Rθ,u V                                                       



也可说四元组r代表了旋转Rθ,u因为r与公式v → rvr^(−1) 一一对应(实际上我们知道是 rVr^(-1)才代表Rθ,u V ) .


好了,下面解释为什么q和-q代表相同的旋转,虽然前面已经解释了对一个四元组乘以一个标量并不影响它所代表的旋转.但是这里我们从几何角度去理解,可能会更加形象.





接下来,我们用第二种方法证明pvp^(-1)代表的是一个旋转变换

Let q = s + v be a unit quaternion. Then q^(-1) = s- v,and given a vector u(注意向量可以看成标量为0的特殊四元组),we have

A(u)=quq^(-1)=(s+v)u(s-v)=(s;v)(0;u)(s;-v)   (通过四元组乘积公式(<s_1;v_1>)(<s_2;v_2>)=s_1s_2-v_1·v_2+s_1v_2+s_2v_1+v_1×v_2)

       =(-v·u+su+v×u)(s;-v)=(-v·u;su+v×u)(s;-v)=-(v·u)s-(su+v×u)·(-v)+(-v·u)(-v)+s(su+v×u)+(su+v×u)×(-v)

       =-(v·u)s+su·v+(v·u)v+s^2u+s(v×u)-s(u×v)-v×u×v

       =s^2u+2s(v×u)+(v·u)v-v×u×v

利用公式P × (Q× P) = P ×Q× P = P^2Q − (P ⋅Q)P

A(u)=s^2u+2s(v×u)+(v·u)v-(v^2u-(v⋅u)v)

       =(s^2-v^2)u+2s(v×u)+2(v·u)v

令v=tv',v'是一个单位向量(注意q是单位四元组,并不能满足v是单位向量)

则A(u)=quq^(-1)=(s^2-t^2)u+2st(v'×u)+2t^2(v'·u)v'


回忆<<各种变换的原理>>里面讲的绕任意轴旋转的公式



我们假设

s^2-t^2=cosθ

2st=sinθ

2t^2=1-cosθ

我们可以求出


The first and third equalities together tell us that s^2 + t^2 =1, so we must have
s = cos(θ/2).

A(u)=quq^(-1)=ucosθ+(v'×u)sinθ+(v'·u)v'(1-cosθ)

这里证明了,A变换表示旋转

四元组q=cos(θ/2)+sin(θ/2)v'



如果用3x3矩阵代表旋转,当表示2个旋转时,需要两个矩阵相乘,用到9*(3+2)操作(9个元素,每个元素需要3次乘法和2次加法)

然而用四元组代表旋转,当表示2个旋转时,需要两个四元组相乘,用到4*4+(4*4-1)次操作(4*4次乘法,4*4-1次加法)




接着我们再从概念上证明四元组代表旋转


在我的那篇<<各种变换的原理>>里面讲过了,


Every rigid, orientation-preserving, linear transformation is a rotation.


A transformation on R^2 is any mapping A : R^2 → R^2. That is, each point x ∈ R^2 is mapped
to a unique point, A(x), also in R^2.
Definition Let A be a transformation. A is a linear transformation provided the following two
conditions hold:
1. For all α ∈ R and all x ∈ R^2, A(αx) = αA(x).
2. For all x, y ∈ R^2, A(x + y) = A(x) + A(y).



For linear transformations, an equivalent definition of rigid transformation is that a linear
transformation A is rigid if and only if it preserves dot products. That is to say, if and only if, for
all x, y ∈ R^2, x · y = A(x) · A(y). 



下面我们来证明v -> qvq(-1)变换拥有这几个性质


A rotation in three dimensions can be thought of as a function A that maps R^3
onto itself. For A to represent a rotation, it must preserve lengths, angles, and handedness(也就是我们说的朝向保持).


The set of quaternions, known by mathematicians as the ring of Hamiltonian quaternions
and denoted by H, can be thought of as a four-dimensional vector space
for which an element q has the form 

q = <w, x, y, z> = w+ xi + yj + zk.

A quaternion is often written as q = s + v, where s represents the scalar part corresponding
to the w-component of q, and v represents the vector part corresponding
to the x, y, and z components of q.

Extending the function A to a mapping from H onto itself by requiring that A(s + v) = s + A(v) 

所以我们只需要证明A(v)变换满足长度保持,角度保持,朝向保持以及线性变换



这里为了与前面一致,我们将其中的v换成u,即证明A(u)变换满足长度保持,角度保持,朝向保持以及线性变换

先证明其满足线性变换

由前面可知

A(u)=(s^2-v^2)u+2s(v×u)+2(v·u)v

A(au)=(s^2-v^2)au+2s(v×au)+2(v·au)v=a((s^2-v^2)u+2s(v×u)+2(v·u)v)=aA(u)

A(u_1+u_2)=(s^2-v^2)(u_1+u_2)+2s(v×(u_1+u_2))+2(v·(u_1+u_2))v

=(s^2-v^2)u_1+(s^2-v^2)u_2+2s(v×u_1)+2s(v×u_2)+2(v·u_1)v+2(v·u_2)v

=(s^2-v^2)u_1+2s(v×u_1)+2(v·u_1)v+(s^2-v^2)u_2+2s(v×u_2)+2(v·u_2)v

=A(u_1)+A(u_2)

这就证明了A满足线性变换


下面我们证它满足长度保持

||A(u)||=||quq^(-1)||=||q|| ||u|| ||q^(-1)|| = ||u||


下面我们需要证明它满足角度保持和朝向保持

由于长度保持已证,所以

角度保持可以通过A(u_1)·A(u_2)=u_1·u_2来证

朝向保持可以通过A(u_1)×A(u_2)=A(u_1×u_2)来证


证角度保持和朝向保持  等价与  证A(u_1)A(u_2)=A(u_1u_2)


为什么呢?请看下面解释


把u_1,u_2,A(u_1),A(u_2)看成特殊的四元组(标量部分为0的四元组)

A(u_1)A(u_2)=-A(u_1)·A(u_2)+A(u_1)×A(u_2)

A(u_1u_2)=A(-u_1·u_2+u_1×u_2)=-u_1·u_2+A(u_1×u_2)   (注意标量部分相等,向量部分相等)

如果证得A(u_1)A(u_2)=A(u_1u_2),那么我们就得到了

A(u_1)·A(u_2)=u_1·u_2和A(u_1)×A(u_2)=A(u_1×u_2)

即角度保持和朝向保持



下面我们证明A满足A(u_1)A(u_2)=A(u_1u_2)


A(u_1)A(u_2)=q(u_1)q^(-1)q(u_2)q^(-1)=q(u_1)(u_2)q^(-1)=A(u_1u_2)


即证明了A满足了角度保持和朝向保持,加上前面的线性变换,我们可知A表示一个旋转变换



///////////////////////至此 四元组能表示旋转的问题被阐明了,如果你只对四元组表示的旋转部分感兴趣可以跳过下面这段内容  如果你想把四元组搞清楚,请你继续////////////


这段我们会说明为什么是θ/2而不是θ,以及为什么旋转变换是表达式quq^(-1)

前面我们说了

四元组q< cos(θ/2) ;sin(θ/2)u>(其中u是单位向量),那么对于向量v,表达式qvq^(-1)得到的结果就是v绕定轴u按右手法则旋转θ度.

从公式上我们知道为什么是cos(θ/2)和sin(θ/2).下面从数学的角度更形象的阐述为什么是θ/2,而不是θ


We begin by considering how we can embed the set of real numbers in
the set of 2×2 matrices. For any given scalar a, we associate it with exactly
one 2 × 2 matrix, namely the matrix that has a on both of the diagonal
elements:


We have chosen a subset of the 2×2 matrices, and established a one-to-one
correspondence between this smaller set of matrices and the set of all real
numbers. We could have established this one-to-one relationship in other
ways, but this particular way of doing it is important because it preserves
all the ordinary algebra laws of addition, subtraction, and multiplication:
the associative property, distributive property, nonfactorability of zero, and
so on. (We can even include division if we treat division as multiplication
by the inverse.) For example,


Now let’s see if we can create a similar mapping for the set of complex
numbers. You probably already have been introduced to complex numbers;
if so, you should remember that the complex pair (a, b) defines the number
a+bi. The number i is a special number such that i^2 = −1. It’s often called
the imaginary number because no ordinary scalar (a “real” number) can
have this property. The word “imaginary” gives one the impression that
the number doesn’t really exist; we’re going avoid this term and instead
stick with the more descriptive one: “complex.”


Complex numbers can be added, subtracted, and multiplied. All we
need to do is follow the ordinary rules for arithmetic, and replace i^2 with
−1 whenever it appears. This results in the following identities:




Now, how can we extend our system of embedding numbers in the space
of 2 × 2 matrices to include complex numbers? Before, we only had one
degree of freedom, a, and now we have two, a and b. The mapping we use is



We can easily verify that the complex number on the left behaves exactly
the same as the matrix on the right. In a certain sense, they are just two
notations for writing the same quantity:


We also verify that the equation i2 = 1 still holds:


我们知道,

矩阵  实际上代表了逆时针旋转90度.

We can interpret multiplication by i as a 90°rotation.

There’s nothing “imaginary” about this. Instead of thinking of i as the
square root of .1, think instead of the complex number a+bi as a mathematical
entity with two degrees of freedom that behaves in particular ways
when multiplied. The part we usually call the “real” part, a, is the main
degree of freedom, and b measures some secondary degree of freedom. The
two degrees of freedom are in some sense “orthogonal” to one another.
Continuing this further, we see that we can represent rotations by any
arbitrary angle θ using this scheme. The basic 2×2 rotation matrix derived
in Section 5.1.1 happens to be in this special set of matrices that we are
mapping to the complex numbers. It maps to the complex number cos θ +
i sin θ:


Notice how complex conjugation (negating the complex part) corresponds
to matrix transposition. This is particularly pleasing. Remember
that the conjugate of a quaternion expresses the inverse angular displacement.
A corresponding fact is true for transposing rotation matrices: since
they are orthogonal, their transpose is equal to their inverse.


How do ordinary 2D vectors fit into this scheme? We interpret the
vector [x, y] as the complex number x + iy, and then we can interpret the multiplication of two complex numbers


as performing a rotation. This is equivalent to the matrix multiplication


While this a not much more that mathematical trivia so far, our goal is to
build up some parallels that we can carry forward to quaternions, so let’s
repeat the key result.

In 2D, we can interpret the vector [x, y] as a complex number x + yi and
rotate it by using the complex multiplication (cos θ + i sin θ)(x + iy).


A similar conversion from ordinary vectors to complex numbers is necessary
in order to multiply quaternions and 3D vectors.




Before we leave 2D, let’s summarize what we’ve learned so far. Complex
numbers are mathematical objects with two degrees of freedom that obey
certain rules when we multiply them. These objects are usually written as
a + bi, but can equivalently be written as a 2 × 2 matrix. When we write
complex numbers as matrices, it begs the geometric interpretation of multiplication
by i as a 90° rotation. The rule i^2 = −1 has the interpretation
that combining two 90° rotations yields a 180° rotation, and that leaves us
with a warm fuzzy feeling. More generally, any complex number with unit
length can be written as cos θ + i sin θ and interpreted as a rotation by the
angle θ. If we convert a 2D vector into complex form and multiply it by
cos θ + i sin θ, it has the effect of performing the rotation.



It’s very tempting to extend this trick from 2D into 3D.

那么这种新复数应该怎样表示呢?The Irish mathematician William Hamilton (1805–1865),也就是发明四元组这位牛人,最开始以为这种复数有一个实部和两个虚部

但在1843,在他去爱尔兰皇家学院的路上,他突然灵感一现,认识到这种复数要有三个虚部,他在Broom Bridge刻下了描述这种新型复数的方程.4元组因此也就产生



那么为什么不用3D复数来表示3D中的旋转呢?

A 3D complex number would have two
complex parts, i and j, with the properties i^2 = j^2 = −1. (We would
also need to define the values of the products ij and ji. Exactly what
these rules should be, we’re not sure; perhaps Hamilton realized this was
a dead end. In any case, it doesn’t matter for the present discussion.)

The number 1 must obviously map to the 3D identity matrix I_3. The number −1 should map
to its negative, −I_3, which has −1s on the diagonal.

现在的问题是我们需要找到i,j能映射到的3x3矩阵.我们马上就会发现,我们找不到这样的映射.为什么呢?

因为−I_3行列式的值为-1.如果找到这样的矩阵,那么这个矩阵行列式的值的平方为-1,

The only way this can work is for i and
j to contain entries that are complex. In short, there doesn’t seem to be
a coherent system of 3D complex numbers; certainly there isn’t one that
maps elegantly to rotations analogously to standard complex numbers and
2D rotations. For that, we need quaternions.

Quaternions extend the complex number system by having three imaginary
numbers, i, j, and k, which are related by Hamilton’s famous equations:


The quaternion we have been denoting <w;(x, y, z)> corresponds to the complex
number w + xi + yj + zk.

Now we return to matrices. Can we embed the set of quaternions into
the set of matrices such that Hamilton’s rules in Equation still hold?


Yes, we can, although, as you might expect, we map them to 4×4 matrices.
Real numbers are mapped to a matrix with the number on each entry of
the diagonal as before,


and the complex quantities are mapped to the matrices

(8.11)


(自己去验证下)

Combining the above associations, we can map an arbitrary quaternion
to a 4 × 4 matrix as


Once again, we notice how complex conjugation (negating x, y, and z)
corresponds to matrix transposition.

Notice how the upper left 2×2 portion of the
k matrix is the same as the very first 2×2 matrix for i; in other words, part
of k is a 90o rotation about z. By analogy with the 2D case, we might reasonably
expect the quaternion cos θ + k sin θ to represent a rotation about
the z-axis by an arbitrary angle θ. Let’s multiply it by the vector [1, 0, 0]
and see what happens.

As in the 2D case, we need to “promote” the vector
into the complex domain; what’s different here is that quaternions have an
extra number. We’ll map [x, y, z] to the complex number 0 + xi + yj + zk,
so the vector [1, 0, 0] is simply i. Expanding the multiplication, we have

(cos θ + k sin θ)i = i cos θ + ki sin θ,

= i cos θ + j sin θ,

which corresponds to [cos θ, sin θ, 0], exactly what we would expect when
rotating the x-axis about the z-axis. So far, all is good. Let’s try a slightly

more general vector [1, 0, 1], which is represented in the complex domain as
i + k:

(cos θ + k sin θ)(i + k) = i cos θ + k cos θ + ki sin θ + k^2 sin θ
= i cos θ + j sin θ + k cos θ -sin θ.                                                              (8.13)

This result does not correspond to a vector at all, since it has a nonzero
value for w. The rotation in the xy-plane worked as expected, but unfortunately,
the z component did not come out right. There is unwanted
rotation in the zw-hyperplane. This is made perfectly clear by looking at
how (cos θ + k sin θ) is represented as a 4 × 4 matrix:


The upper-left 2 × 2 rotation matrix is the one we want; the lower-right
2 × 2 rotation matrix is not wanted.


Now we are left wondering if maybe we did something wrong.

Perhaps, instead, our problem is that we did the multiplication in the
wrong order. (After all, multiplication of i, j, and k is not commutative.)
Let’s try putting the vector on the left and the rotation quaternion on the
right:

(i + k)(cos θ + k sin θ) = i cos θ + ik sin θ + k cos θ + k^2 sin θ
= i cos θ − j sin θ + k cos θ − sin θ.

Comparing this to Equation (8.13), when the operands were in the opposite
order, we see that the only difference is the sign of the y-coordinate. At first
glance, it looks like this is actually worse. The rotation in the xz-plane that
we want got inverted; now we have a rotation by −θ. Meanwhile, the extra
rotation we didn’t want is exactly the same as before. But perhaps you can
already see the solution. If we use the opposite rotation, which corresponds
to using the conjugate of the quaternion, we fix both problems:

(i + k)(cos θ − k sin θ) = i cos θ + j sin θ − k cos θ + sin θ.

So, multiplying on the left by (cos θ + k sin θ) produced the rotation we
wanted, plus some extra rotation we didn’t want, and multiplication on

the right by the conjugate achieved the same rotation that was desired,
with the opposite undesired rotation. If we combine these two steps, the
unwanted rotation is canceled out, and we are left with only the rotation
we want. Well, not quite, we are left with twice the rotation we want, but
this is easily fixed by using θ/2 instead of θ. Of course, we knew that θ/2
would appear somewhere, but now we see the reason. Let’s summarize our
findings from the preceding paragraphs.



注意我们的变换公式是qvq^(-1),而这里是qvq*,有没有区别呢?

如果q是单位四元组,没有影响因为q^(-1)=q*.

如果q不是单位四元组,那么可以把q表示为q=au,其中u为单位四元组


那么qvq^(-1)=auvu^(-1)(1/a)=uvu^(-1)   

而qvq*=auvau*=auvu^(-1)a=a^2uvu^(-1)

说明qvq^(-1),无论q的长度如何变化,他所表示的始终是一个旋转

而qvq*,如果q的长度增加a倍,那么qvq*所表示的不光是一个旋转,而且还把v的长度增加了a^2倍


////////////////////////////////////////////////////////////////////////////////本段结束///////////////////////////////////////////////////////////////////

如果你想绕(xx,yy,zz)逆时针旋转dAngle度,可以用下面这个函数产生四元组,进而进行旋转

		Quaternion FromAngleAxis(const double dAngle,double xx,double yy,double zz)
		{
			double dHalfAngle=dAngle/2*3.14159265358979323846/180;
			w=cos(dHalfAngle);
			double dSinHalfAngle=sin(dHalfAngle);
			x=xx*dSinHalfAngle;
			y=yy*dSinHalfAngle;
			z=zz*dSinHalfAngle;
			return Quaternion(w,x,y,z);
		}

下面介绍四元组的插值运算

Because quaternions are represented by vectors, they are well suited for interpolation.
When an object is being animated, interpolation is useful for generating
intermediate orientations that fall between precalculated key frames.

The simplest type of interpolation is linear interpolation. For two unit quaternions
q_1 and q_2, the linearly interpolated quaternion q(t) is given by


The function q(t) changes smoothly along the line segment connecting q_1 and q_2
as t varies from 0 to 1. As shown in Figure 4.7, q(t ) does not maintain the unit
length of q_1 and q_2, but we can renormalize at each point by instead using the
function







There are two slight complications. First, the two quaternions q and
−q represent the same orientation, but may produce different results when

used as an argument to slerp. This problem doesn’t happen in 2D or 3D,
but the surface of a 4D hypersphere has a different topology than Euclidian
space. The solution is to choose the signs of q1and q2 such that the dot
product q1 · q2 is nonnegative. This has the effect of always selecting the
shortest rotational arc from q1 to q2. The second complication is that if
q1 and q2 are very close, then θ is very small, and thus sinθ  is also very
small, which will cause problems with the division. To avoid this, if sinθ
is very small, we will use simple linear interpolation. 


下面解释为什么q1·q2 >= 0时,q1到q2是最短路径

we considered the difference quaternion d = ba*, which describes the angular displacement
from orientation a to orientation b. (We assume unit quaternions and replace
the quaternion inverse with the conjugate.) If we expand the product
and examine the contents of d, we find that the w component is equal to
the dot product a · b


设b=<s_b;v_b>,a=<s_a;v_a>

则a*=<s_a;-v_a>

ba*=<s_b;v_b><s_a;-v_a>

     =s_bs_a+v_a·v_b-s_bv_a+s_av_b-v_b×v_a


What does this mean geometrically? Remember Euler’s rotation theorem:
we can rotate from the orientation a into the orientation b via a
single rotation about a carefully chosen axis. This uniquely determined
(up to a reversal of sign) axis and angle are precisely the ones encoded in
d. Remembering the relationship between the w component and the rotation
angle θ, we see that a·b = cos(θ/2), where θ is the amount of rotation
needed to go from the orientation a to the orientation b.

In summary, the quaternion dot product has an interpretation similar to
the vector dot product. The larger the absolute value of the quaternion dot
product a·b, the more “similar” are the angular displacements represented
by a and b. While the vector dot product gives the cosine of the angle
between vectors, the quaternion dot product gives the cosine of half of the
angle needed to rotate one quaternion into the other. For the purpose of
measuring similarity, usually we are interested only in the absolute value
of a · b, since a · b = −(a · −b), even though b and −b represent the same
angular displacement.

这就说明了为什么q1·q2 >= 0时,q1到q2是最短路径


下面给出四元组球形插值的函数

Quaternion Slerp(double dt,const Quaternion &q1,const Quaternion &q2,bool shortestPath)
	{
		double dCos=q1.Dot(q2);
		Quaternion q3;
		if(dCos<0 && shortestPath)
		{
			dCos=-dCos;
			q3=-q2;
		}	
		else
		{
			q3=q2;
		}

		if(abs(dCos)< 1 - 1e-6)
		{
			double dSin=sqrt(1-dCos*dCos);
			double dAngle=atan2(dSin,dCos);//这样写后面的结果为1,无需将结果单位化
			//double dAngle=atan(dSin/dCos);//不知道为何这样写的话,后面的插值结果长度不为1,需要将结果单位化
			double dSinInv=1/dSin;
			double dCoeff0=sin((1-dt)*dAngle)*dSinInv;
			double dCoeff1=sin(dt*dAngle)*dSinInv;
			Quaternion	q= dCoeff0*q1+dCoeff1*q3;
			//return q.Normalize();
			return q;
		}
		else//采用线性插值
		{
			Quaternion t=(1.0 - dt)*q1 + dt*q3;
			t=t.Normalize();
			return t;
		}


	}

下面介绍四元组到3x3矩阵的相互转换


Because a quaternion represents a rotation, its action on R^3 can be represented by a 3 × 3
matrix. We now show how to convert a quaternion q into a 3 × 3 matrix. 

a transformation A(v) is represented by the matrix (w_1 w_2 w_3),


where the columns wi are equal to A(i), A(j), and A(k). Thus, to represent a quaternion q by
a matrix, we set
w_1 = qiq^(−1), w_2 = qjq^(−1), and w3 = qkq^(−1)


四元组转3x3旋转矩阵的函数如下:

		operator Matrix3x3()
		{
			(*this)=(*this).Normalize();
			Matrix3x3 m;
			double ww=w*w;
			double xx=x*x;
			double yy=y*y;
			double zz=z*z;
			double xy=x*y;
			double xz=x*z;
			double xw=x*w;
			double yz=y*z;
			double yw=y*w;
			double zw=z*w;
			m(0,0)=ww+xx-yy-zz;
			m(0,1)=2*xy-2*zw;
			m(0,2)=2*xz+2*yw;
			m(1,0)=2*xy+2*zw;
			m(1,1)=ww-xx+yy-zz;
			m(1,2)=2*yz-2*xw;
			m(2,0)=2*xz-2*yw;
			m(2,1)=2*yz+2*xw;
			m(2,2)=ww-xx-yy+zz;
			return m;
		}






3x3旋转矩阵转四元组

Quaternion(Matrix3x3& m)
		{
			double d=m(0,0)+m(1,1)+m(2,2),max;
			max= m(0,0)>m(1,1) ? (m(0,0)>m(2,2) ? m(0,0) : m(2,2)) : (m(1,1)>m(2,2)?m(1,1):m(2,2) );
			if(d>max)
			{
				w=0.5*sqrt(d+1);
				x=0.25*(m(2,1)-m(1,2))/w;
				y=0.25*(m(0,2)-m(2,0))/w;
				z=0.25*(m(1,0)-m(0,1))/w;
			}
			else if(max == m(0,0))
			{
				x=0.5*sqrt(2*m(0,0)-d+1);
				w=0.25*(m(2,1)-m(1,2))/x;
				y=0.25*(m(1,0)+m(0,1))/x;
				z=0.25*(m(0,2)+m(2,0))/x;
			}
			else if(max== m(1,1))
			{
				y=0.5*sqrt(2*m(1,1)-d+1);
				w=0.25*(m(0,2)-m(2,0))/y;
				x=0.25*(m(1,0)+m(0,1))/y;
				z=0.25*(m(2,1)+m(1,2))/y;
			}
			else if(max == m(2,2))
			{
				z=0.5*sqrt(2*m(2,2)-d+1);
				w=0.25*(m(1,0)-m(0,1))/z;
				x=0.25*(m(0,2)+m(2,0))/z;
				y=0.25*(m(2,1)+m(1,2))/z;
			}
			
		}


main函数它们相互转换如下:

	Seamanj::Quaternion q;
	q.FromAngleAxis(90,1,1,0);
	q.Normalize();
	cout<<q.x<<' '<<q.y<<' '<<q.z<<' '<<q.w<<endl;
	Seamanj::Matrix3x3 m=(Seamanj::Matrix3x3)q;
	std::cout<<m<<std::endl;
	Seamanj::Matrix3x3 m1(m);
	Seamanj::Quaternion q1(m1);
	cout<<q1.x<<' '<<q1.y<<' '<<q1.z<<' '<<q1.w<<endl;
结果如下:



显示函数里调用四元组插值部分代码:

	Seamanj::Quaternion qRotateToBlueLine,qRotateToMagentaLine,qRotateToGreenLine,qRotateToRedLine,qRotateToCyanLine;
	Seamanj::Quaternion q_OriginOrientation(0,2,1,0),q_BlueLineOrientation,q_MagentaLineOrientation,q_GreenLineOrientation,q_RedLineOrientation,q_CyanLineOrientation;
	q_OriginOrientation=q_OriginOrientation.Normalize();
	qRotateToBlueLine.FromAngleAxis(dMyAngle,0,1,0);
	//cout<<"qRotateToBlueLine len:"<<qRotateToBlueLine.Norm()<<endl;
	qRotateToMagentaLine.FromAngleAxis(dMyAngle+90,0,1,0);
	//cout<<"qRotateToMagentaLine len:"<<qRotateToBlueLine.Norm()<<endl;
	qRotateToGreenLine.FromAngleAxis(dMyAngle,1,0,0);
	//cout<<"qRotateToGreenLine len:"<<qRotateToGreenLine.Norm()<<endl;
	qRotateToRedLine=Slerp(dt_Red_between_Blue_and_Green,qRotateToBlueLine,qRotateToGreenLine);
	//cout<<"qRotateToRedLine len:"<<qRotateToRedLine.Norm()<<endl;
	qRotateToCyanLine=Slerp(dt_Cyan_between_Magenta_and_Greeen,qRotateToMagentaLine,qRotateToGreenLine,false);//不用最路径,以看插值的连续性
	//cout<<"qRotateToCyanLine len:"<<qRotateToCyanLine.Norm()<<endl;

	q_BlueLineOrientation=qRotateToBlueLine*q_OriginOrientation*qRotateToBlueLine.UnitInverse();//BLUE LINE
	q_MagentaLineOrientation=qRotateToMagentaLine*q_OriginOrientation*qRotateToMagentaLine.UnitInverse();//MAGENTA LINE
	q_GreenLineOrientation=qRotateToGreenLine*q_OriginOrientation*qRotateToGreenLine.UnitInverse();//GREEN LINE
	q_RedLineOrientation=qRotateToRedLine*q_OriginOrientation*qRotateToRedLine.UnitInverse();//RED LINE
	q_CyanLineOrientation=qRotateToCyanLine*q_OriginOrientation*qRotateToCyanLine.UnitInverse();//CYAN LINE
	



	glBegin(GL_LINES);

	//用白色的线画坐标轴
	glColor3f(1,1,1);
	glVertex3f(0,0,0);
	glVertex3f(10,0,0);
	glVertex3f(0,0,0);
	glVertex3f(0,10,0);
	glVertex3f(0,0,0);
	glVertex3f(0,0,10);
	
	//画蓝线
	glColor3f(0,0,1);
	glVertex3f(0,0,0);
	glVertex3f(3*q_BlueLineOrientation.x,3*q_BlueLineOrientation.y,3*q_BlueLineOrientation.z);

	//画洋红色线
	glColor3f(1,0,1);
	glVertex3f(0,0,0);
	glVertex3f(3*q_MagentaLineOrientation.x,3*q_MagentaLineOrientation.y,3*q_MagentaLineOrientation.z);

	//画绿线
	glColor3f(0,1,0);
	glVertex3f(0,0,0);
	glVertex3f(3*q_GreenLineOrientation.x,3*q_GreenLineOrientation.y,3*q_GreenLineOrientation.z);

	//画红线
	glColor3f(1,0,0);
	glVertex3f(0,0,0);
	glVertex3f(3*q_RedLineOrientation.x,3*q_RedLineOrientation.y,3*q_RedLineOrientation.z);
	
	//画青色线
	glColor3f(0,1,1);
	glVertex3f(0,0,0);
	glVertex3f(3*q_CyanLineOrientation.x,3*q_CyanLineOrientation.y,3*q_CyanLineOrientation.z);

	glEnd();


运行结果如下:


红色线在蓝色和绿色之间按0到1再到0,如此循环进行球形插值,即红色线将会在蓝色线和绿色线之间摆动


青色线0.5的比例在洋红色线和绿色线之间进行球形插值


最后给源代码:

Quaternion.h头文件

#ifndef _QUATERNION
#define _QUATERNION
#include <iostream>
#include <iomanip>
namespace Seamanj
{
	class Matrix3x3
	{
	public:
		Matrix3x3()
		{
			for(int i=0;i<3;i++)
				for(int j=0;j<3;j++)
					data[i][j]=0.0;
		}
		Matrix3x3(double* pd)
		{
			for(int i=0;i<3;i++)
				for(int j=0;j<3;j++)
					data[i][j]=pd[i*3+j];
		}
		Matrix3x3(const Matrix3x3& m)
		{
			for(int i=0;i<3;i++)
				for(int j=0;j<3;j++)
					data[i][j]=m(i,j);
		}

		double data[3][3];
		double& operator()(int i,int j)
		{
			return data[i][j];
		}
		double operator()(int i,int j) const
		{
			return data[i][j];
		}
		friend std::ostream& operator<<(std::ostream& os,Matrix3x3& m);
	};
	std::ostream& operator<<(std::ostream& os,Matrix3x3& m)
	{
		for(int i=0;i<3;i++)
		{
			for(int j=0;j<3;j++)
			{
				os<<std::setw(10)<<((m(i,j)<1e-6 && m(i,j)>-1e-6)?0.0:m(i,j))<<'\t';
			}
			os<<std::endl;
		}
		return os;
	}
	class Quaternion
	{
	public:
		double w,x,y,z;
		Quaternion(double ww=1,double xx=0,double yy=0,double zz=0)
		{
			w=ww;
			x=xx;
			y=yy;
			z=zz;
		}
		Quaternion(Matrix3x3& m)
		{
			double d=m(0,0)+m(1,1)+m(2,2),max;
			max= m(0,0)>m(1,1) ? (m(0,0)>m(2,2) ? m(0,0) : m(2,2)) : (m(1,1)>m(2,2)?m(1,1):m(2,2) );
			if(d>max)
			{
				w=0.5*sqrt(d+1);
				x=0.25*(m(2,1)-m(1,2))/w;
				y=0.25*(m(0,2)-m(2,0))/w;
				z=0.25*(m(1,0)-m(0,1))/w;
			}
			else if(max == m(0,0))
			{
				x=0.5*sqrt(2*m(0,0)-d+1);
				w=0.25*(m(2,1)-m(1,2))/x;
				y=0.25*(m(1,0)+m(0,1))/x;
				z=0.25*(m(0,2)+m(2,0))/x;
			}
			else if(max== m(1,1))
			{
				y=0.5*sqrt(2*m(1,1)-d+1);
				w=0.25*(m(0,2)-m(2,0))/y;
				x=0.25*(m(1,0)+m(0,1))/y;
				z=0.25*(m(2,1)+m(1,2))/y;
			}
			else if(max == m(2,2))
			{
				z=0.5*sqrt(2*m(2,2)-d+1);
				w=0.25*(m(1,0)-m(0,1))/z;
				x=0.25*(m(0,2)+m(2,0))/z;
				y=0.25*(m(2,1)+m(1,2))/z;
			}
			
		}
		operator Matrix3x3()
		{
			(*this)=(*this).Normalize();
			Matrix3x3 m;
			double ww=w*w;
			double xx=x*x;
			double yy=y*y;
			double zz=z*z;
			double xy=x*y;
			double xz=x*z;
			double xw=x*w;
			double yz=y*z;
			double yw=y*w;
			double zw=z*w;
			m(0,0)=ww+xx-yy-zz;
			m(0,1)=2*xy-2*zw;
			m(0,2)=2*xz+2*yw;
			m(1,0)=2*xy+2*zw;
			m(1,1)=ww-xx+yy-zz;
			m(1,2)=2*yz-2*xw;
			m(2,0)=2*xz-2*yw;
			m(2,1)=2*yz+2*xw;
			m(2,2)=ww-xx-yy+zz;
			return m;
		}


		Quaternion operator*(Quaternion q)
		{
			return Quaternion(w*q.w-x*q.x-y*q.y-z*q.z,w*q.x+x*q.w+y*q.z-z*q.y,
				w*q.y-x*q.z+y*q.w+z*q.x,w*q.z+x*q.y-y*q.x+z*q.w);
		}
		friend Quaternion operator*(double dScalar,const Quaternion& q);
		Quaternion operator*(const double d)
		{
			return Quaternion(w*d,x*d,y*d,z*d);
		}
		Quaternion operator+ (const Quaternion& q) const
		{
			return Quaternion(w+q.w,x+q.x,y+q.y,z+q.z);
		}
		Quaternion operator- (const Quaternion& q) const
		{
			return Quaternion(w-q.w,x-q.x,y-q.y,z-q.z);
		}

		Quaternion operator- () const
		{
			return Quaternion(-w,-x,-y,-z);
		}
		Quaternion UnitInverse() const
		{
			// assert:  'this' is unit length
			return Quaternion(w,-x,-y,-z);
		}
		double Norm() const
		{
			return w*w+x*x+y*y+z*z;
		}
		Quaternion Normalize()
		{
			double len=Norm();
			double factor=1/sqrt(len);
			*this=*this * factor;
			return *this;
		}
		Quaternion FromAngleAxis(const double dAngle,double xx,double yy,double zz)
		{
			double dHalfAngle=dAngle/2*3.14159265358979323846/180;
			w=cos(dHalfAngle);
			double dSinHalfAngle=sin(dHalfAngle);
			x=xx*dSinHalfAngle;
			y=yy*dSinHalfAngle;
			z=zz*dSinHalfAngle;
			return Quaternion(w,x,y,z);
		}
		double Dot(const Quaternion& q) const  // dot product
		{
			return w*q.w+x*q.x+y*q.y+z*q.z;
		}
		friend Quaternion Slerp(double dt,const Quaternion &q1,const Quaternion &q2,bool shortestPath=true);
	};
	Quaternion operator*(double d,const Quaternion& q)
	{
		return Quaternion(q.w*d,q.x*d,q.y*d,q.z*d);
	}
	Quaternion Slerp(double dt,const Quaternion &q1,const Quaternion &q2,bool shortestPath)
	{
		double dCos=q1.Dot(q2);
		Quaternion q3;
		if(dCos<0 && shortestPath)
		{
			dCos=-dCos;
			q3=-q2;
		}	
		else
		{
			q3=q2;
		}

		if(abs(dCos)< 1 - 1e-6)
		{
			double dSin=sqrt(1-dCos*dCos);
			double dAngle=atan2(dSin,dCos);//这样写后面的结果为1,无需将结果单位化
			//double dAngle=atan(dSin/dCos);//不知道为何这样写的话,后面的插值结果长度不为1,需要将结果单位化
			double dSinInv=1/dSin;
			double dCoeff0=sin((1-dt)*dAngle)*dSinInv;
			double dCoeff1=sin(dt*dAngle)*dSinInv;
			Quaternion	q= dCoeff0*q1+dCoeff1*q3;
			//return q.Normalize();
			return q;
		}
		else//采用线性插值
		{
			Quaternion t=(1.0 - dt)*q1 + dt*q3;
			t=t.Normalize();
			return t;
		}


	}

}

#endif _QUATERNION

main.cpp头文件

//1 add Cg Frame
//2 add fragment program
//3 get and set variable in vertex shader and fragment shader
//4 add Matrix<--->Quaternion 
#include <stdio.h>
#include <stdlib.h>
#include <cg/cg.h>
#include <cg/cgGL.h>
#include <gl/glut.h>
#include <math.h>
#include <assert.h>
#include <iostream>
#include "Quaternion.h"
using std::cout;
using std::endl;
static CGcontext myCgContext;
static CGprofile myCgVertexProfile;
static CGprogram myCgVertexProgram;
//2 begin
static CGprofile myCgFragmentProfile;
static CGprogram myCgFragmentProgram;
//2 end
static const char* myProgramName="Quaternion";
static const char* myVertexProgramFileName="MyVertex.cg";
static const char* myVertexProgramEntryFunctionName="MyVertexEntry";

//3 begin
static CGparameter myCgVertexParam_modelViewProj;      
static double dMyAngle=0;
static double dt_Red_between_Blue_and_Green=0;
static double dt_Cyan_between_Magenta_and_Greeen=0;
static float myProjectionMatrix[16];
//3 end

static void checkForCgError(const char *situation)
{
	CGerror error;
	const char *string = cgGetLastErrorString(&error);

	if (error != CG_NO_ERROR) 
	{
		printf("%s: %s: %s\n",myProgramName, situation, string);
		if (error == CG_COMPILER_ERROR) 
			printf("%s\n", cgGetLastListing(myCgContext));
		exit(1);
	}
}
static void display(void);
static void keyboard(unsigned char c,int x,int y);
static void reshape(int width, int height);
int main(int argc,char **argv)
{
	glutInitWindowSize(400,400);
	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
	glutInit(&argc,argv);
	glutCreateWindow(myProgramName);//窗口名字为我们的程序名字
	glutDisplayFunc(display);
	glutKeyboardFunc(keyboard);
	glutReshapeFunc(reshape);
	glClearColor(0.1,0.1,0.1,0.0);
	glEnable(GL_DEPTH_TEST);
	


	myCgContext=cgCreateContext();
	checkForCgError("creating context");
	cgGLSetDebugMode(CG_FALSE);
	cgSetParameterSettingMode(myCgContext,CG_DEFERRED_PARAMETER_SETTING);
	myCgVertexProfile=cgGLGetLatestProfile(CG_GL_VERTEX);
	cgGLSetOptimalOptions(myCgVertexProfile);
	checkForCgError("selecting vertex profile");
	myCgVertexProgram=cgCreateProgramFromFile(
		myCgContext,CG_SOURCE,myVertexProgramFileName,myCgVertexProfile,myVertexProgramEntryFunctionName,NULL);
	checkForCgError("creating vertex program from file");
	cgGLLoadProgram(myCgVertexProgram);
	checkForCgError("loading vertex program");
	//3 begin
	myCgVertexParam_modelViewProj =
	cgGetNamedParameter(myCgVertexProgram, "modelViewProj");
	checkForCgError("could not get modelViewProj parameter");
	//3 end
	//2 begin
	myCgFragmentProfile=cgGLGetLatestProfile(CG_GL_FRAGMENT);
	cgGLSetOptimalOptions(myCgFragmentProfile);
	checkForCgError("selecting fragment profile");
	myCgFragmentProgram=cgCreateProgram(
		myCgContext,CG_SOURCE, "float4 main( float4 c:COLOR) : COLOR { return c; }",myCgFragmentProfile,"main",NULL);
	checkForCgError("creating fragment program from string");
	cgGLLoadProgram(myCgFragmentProgram);
	checkForCgError("loading fragment program");
	//2 end
	//4 begin
	Seamanj::Quaternion q;
	q.FromAngleAxis(90,1,1,0);
	q.Normalize();
	cout<<q.x<<' '<<q.y<<' '<<q.z<<' '<<q.w<<endl;
	Seamanj::Matrix3x3 m=(Seamanj::Matrix3x3)q;
	std::cout<<m<<std::endl;
	Seamanj::Matrix3x3 m1(m);
	Seamanj::Quaternion q1(m1);
	cout<<q1.x<<' '<<q1.y<<' '<<q1.z<<' '<<q1.w<<endl;
	//4 end
	glutMainLoop();
	return 0;
}
//3 begin
static void buildPerspectiveMatrix(double, double,
                                   double, double, float m[16]);

static void reshape(int width, int height)
{
  double aspectRatio = (float) width / (float) height;
  double fieldOfView = 40.0; /* Degrees */

  /* Build projection matrix once. */
  buildPerspectiveMatrix(fieldOfView, aspectRatio,
                         1.0, 20.0,  /* Znear and Zfar */
                         myProjectionMatrix);
  glViewport(0, 0, width, height);
}

static const double myPi = 3.14159265358979323846;
static void buildPerspectiveMatrix(double fieldOfView,
                                   double aspectRatio,
                                   double zNear, double zFar,
                                   float m[16])
{
  double sine, cotangent, deltaZ;
  double radians = fieldOfView / 2.0 * myPi / 180.0;
  
  deltaZ = zFar - zNear;
  sine = sin(radians);
  /* Should be non-zero to avoid division by zero. */
  assert(deltaZ);
  assert(sine);
  assert(aspectRatio);
  cotangent = cos(radians) / sine;

  m[0*4+0] = cotangent / aspectRatio;
  m[0*4+1] = 0.0;
  m[0*4+2] = 0.0;
  m[0*4+3] = 0.0;
  
  m[1*4+0] = 0.0;
  m[1*4+1] = cotangent;
  m[1*4+2] = 0.0;
  m[1*4+3] = 0.0;
  
  m[2*4+0] = 0.0;
  m[2*4+1] = 0.0;
  m[2*4+2] = -(zFar + zNear) / deltaZ;
  m[2*4+3] = -2 * zNear * zFar / deltaZ;
  
  m[3*4+0] = 0.0;
  m[3*4+1] = 0.0;
  m[3*4+2] = -1;
  m[3*4+3] = 0;
}

/* Build a row-major (C-style) 4x4 matrix transform based on the
   parameters for gluLookAt. */
static void buildLookAtMatrix(double eyex, double eyey, double eyez,
                              double centerx, double centery, double centerz,
                              double upx, double upy, double upz,
                              float m[16])
{
  double x[3], y[3], z[3], mag;

  /* Difference eye and center vectors to make Z vector. */
  z[0] = eyex - centerx;
  z[1] = eyey - centery;
  z[2] = eyez - centerz;
  /* Normalize Z. */
  mag = sqrt(z[0]*z[0] + z[1]*z[1] + z[2]*z[2]);
  if (mag) {
    z[0] /= mag;
    z[1] /= mag;
    z[2] /= mag;
  }

  /* Up vector makes Y vector. */
  y[0] = upx;
  y[1] = upy;
  y[2] = upz;

  /* X vector = Y cross Z. */
  x[0] =  y[1]*z[2] - y[2]*z[1];
  x[1] = -y[0]*z[2] + y[2]*z[0];
  x[2] =  y[0]*z[1] - y[1]*z[0];

  /* Recompute Y = Z cross X. */
  y[0] =  z[1]*x[2] - z[2]*x[1];
  y[1] = -z[0]*x[2] + z[2]*x[0];
  y[2] =  z[0]*x[1] - z[1]*x[0];

  /* Normalize X. */
  mag = sqrt(x[0]*x[0] + x[1]*x[1] + x[2]*x[2]);
  if (mag) {
    x[0] /= mag;
    x[1] /= mag;
    x[2] /= mag;
  }

  /* Normalize Y. */
  mag = sqrt(y[0]*y[0] + y[1]*y[1] + y[2]*y[2]);
  if (mag) {
    y[0] /= mag;
    y[1] /= mag;
    y[2] /= mag;
  }

  /* Build resulting view matrix. */
  m[0*4+0] = x[0];  m[0*4+1] = x[1];
  m[0*4+2] = x[2];  m[0*4+3] = -x[0]*eyex + -x[1]*eyey + -x[2]*eyez;

  m[1*4+0] = y[0];  m[1*4+1] = y[1];
  m[1*4+2] = y[2];  m[1*4+3] = -y[0]*eyex + -y[1]*eyey + -y[2]*eyez;

  m[2*4+0] = z[0];  m[2*4+1] = z[1];
  m[2*4+2] = z[2];  m[2*4+3] = -z[0]*eyex + -z[1]*eyey + -z[2]*eyez;

  m[3*4+0] = 0.0;   m[3*4+1] = 0.0;  m[3*4+2] = 0.0;  m[3*4+3] = 1.0;
}



static void makeRotateMatrix(float angle,
                             float ax, float ay, float az,
                             float m[16])
{
  float radians, sine, cosine, ab, bc, ca, tx, ty, tz;
  float axis[3];
  float mag;

  axis[0] = ax;
  axis[1] = ay;
  axis[2] = az;
  mag = sqrt(axis[0]*axis[0] + axis[1]*axis[1] + axis[2]*axis[2]);
  if (mag) {
    axis[0] /= mag;
    axis[1] /= mag;
    axis[2] /= mag;
  }

  radians = angle * myPi / 180.0;
  sine = sin(radians);
  cosine = cos(radians);
  ab = axis[0] * axis[1] * (1 - cosine);
  bc = axis[1] * axis[2] * (1 - cosine);
  ca = axis[2] * axis[0] * (1 - cosine);
  tx = axis[0] * axis[0];
  ty = axis[1] * axis[1];
  tz = axis[2] * axis[2];

  m[0]  = cosine + (1 - cosine) * tx;
  m[1]  = ab - axis[2] * sine;
  m[2]  = ca + axis[1] * sine;
  m[3]  = 0.0f;
  m[4]  = ab + axis[2] * sine;
  m[5]  = cosine + (1 - cosine) * ty;
  m[6]  = bc - axis[0] * sine;
  m[7]  = 0.0f;
  m[8]  = ca - axis[1] * sine;
  m[9]  = bc + axis[0] * sine;
  m[10] = cosine + (1 - cosine) * tz;
  m[11] = 0;
  m[12] = 0;
  m[13] = 0;
  m[14] = 0;
  m[15] = 1;
}

static void makeTranslateMatrix(float x, float y, float z, float m[16])
{
  m[0]  = 1;  m[1]  = 0;  m[2]  = 0;  m[3]  = x;
  m[4]  = 0;  m[5]  = 1;  m[6]  = 0;  m[7]  = y;
  m[8]  = 0;  m[9]  = 0;  m[10] = 1;  m[11] = z;
  m[12] = 0;  m[13] = 0;  m[14] = 0;  m[15] = 1;
}

/* Simple 4x4 matrix by 4x4 matrix multiply. */
static void multMatrix(float dst[16],
                       const float src1[16], const float src2[16])
{
  float tmp[16];
  int i, j;

  for (i=0; i<4; i++) {
    for (j=0; j<4; j++) {
      tmp[i*4+j] = src1[i*4+0] * src2[0*4+j] +
                   src1[i*4+1] * src2[1*4+j] +
                   src1[i*4+2] * src2[2*4+j] +
                   src1[i*4+3] * src2[3*4+j];
    }
  }
  /* Copy result to dst (so dst can also be src1 or src2). */
  for (i=0; i<16; i++)
    dst[i] = tmp[i];
}

//3 end
static void display(void)
{
	//3 begin
	  float translateMatrix[16], rotateMatrix[16],
        modelMatrix[16], viewMatrix[16],
        modelViewMatrix[16], modelViewProjMatrix[16];
	 buildLookAtMatrix(0,0, 13,  /* eye position */
					   0, 0, 0, /* view center */
					   0, 1, 0, /* up vector */
                       viewMatrix);
	//3 end
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	cgGLBindProgram(myCgVertexProgram);
	checkForCgError("binding vertex program");
	cgGLEnableProfile(myCgVertexProfile);
	checkForCgError("enabling vertex profile");
	//2 begin
	cgGLBindProgram(myCgFragmentProgram);
	checkForCgError("binding fragment program");
	cgGLEnableProfile(myCgFragmentProfile);
	checkForCgError("enabling fragment profile");
	//2 end
	//3 begin
	/*** Render green wireframe sphere ***/

	/* modelView = rotateMatrix * translateMatrix */
	makeRotateMatrix(0, 0, 0, 1, rotateMatrix);
	makeTranslateMatrix(0, 0, 0, translateMatrix);
	multMatrix(modelMatrix, translateMatrix, rotateMatrix);

	/* modelViewMatrix = viewMatrix * modelMatrix */
	multMatrix(modelViewMatrix, viewMatrix, modelMatrix);

	/* modelViewProj = projectionMatrix * modelViewMatrix */
	multMatrix(modelViewProjMatrix, myProjectionMatrix, modelViewMatrix);

	/* Set matrix parameter with row-major matrix. */
	cgSetMatrixParameterfr(myCgVertexParam_modelViewProj, modelViewProjMatrix);
	cgUpdateProgramParameters(myCgVertexProgram);
	cgUpdateProgramParameters(myCgFragmentProgram);
	

	Seamanj::Quaternion qRotateToBlueLine,qRotateToMagentaLine,qRotateToGreenLine,qRotateToRedLine,qRotateToCyanLine;
	Seamanj::Quaternion q_OriginOrientation(0,2,1,0),q_BlueLineOrientation,q_MagentaLineOrientation,q_GreenLineOrientation,q_RedLineOrientation,q_CyanLineOrientation;
	q_OriginOrientation=q_OriginOrientation.Normalize();
	qRotateToBlueLine.FromAngleAxis(dMyAngle,0,1,0);
	//cout<<"qRotateToBlueLine len:"<<qRotateToBlueLine.Norm()<<endl;
	qRotateToMagentaLine.FromAngleAxis(dMyAngle+90,0,1,0);
	//cout<<"qRotateToMagentaLine len:"<<qRotateToBlueLine.Norm()<<endl;
	qRotateToGreenLine.FromAngleAxis(dMyAngle,1,0,0);
	//cout<<"qRotateToGreenLine len:"<<qRotateToGreenLine.Norm()<<endl;
	qRotateToRedLine=Slerp(dt_Red_between_Blue_and_Green,qRotateToBlueLine,qRotateToGreenLine);
	//cout<<"qRotateToRedLine len:"<<qRotateToRedLine.Norm()<<endl;
	qRotateToCyanLine=Slerp(dt_Cyan_between_Magenta_and_Greeen,qRotateToMagentaLine,qRotateToGreenLine,false);//不用最路径,以看插值的连续性
	//cout<<"qRotateToCyanLine len:"<<qRotateToCyanLine.Norm()<<endl;

	q_BlueLineOrientation=qRotateToBlueLine*q_OriginOrientation*qRotateToBlueLine.UnitInverse();//BLUE LINE
	q_MagentaLineOrientation=qRotateToMagentaLine*q_OriginOrientation*qRotateToMagentaLine.UnitInverse();//MAGENTA LINE
	q_GreenLineOrientation=qRotateToGreenLine*q_OriginOrientation*qRotateToGreenLine.UnitInverse();//GREEN LINE
	q_RedLineOrientation=qRotateToRedLine*q_OriginOrientation*qRotateToRedLine.UnitInverse();//RED LINE
	q_CyanLineOrientation=qRotateToCyanLine*q_OriginOrientation*qRotateToCyanLine.UnitInverse();//CYAN LINE
	



	glBegin(GL_LINES);

	//用白色的线画坐标轴
	glColor3f(1,1,1);
	glVertex3f(0,0,0);
	glVertex3f(10,0,0);
	glVertex3f(0,0,0);
	glVertex3f(0,10,0);
	glVertex3f(0,0,0);
	glVertex3f(0,0,10);
	
	//画蓝线
	glColor3f(0,0,1);
	glVertex3f(0,0,0);
	glVertex3f(3*q_BlueLineOrientation.x,3*q_BlueLineOrientation.y,3*q_BlueLineOrientation.z);

	//画洋红色线
	glColor3f(1,0,1);
	glVertex3f(0,0,0);
	glVertex3f(3*q_MagentaLineOrientation.x,3*q_MagentaLineOrientation.y,3*q_MagentaLineOrientation.z);

	//画绿线
	glColor3f(0,1,0);
	glVertex3f(0,0,0);
	glVertex3f(3*q_GreenLineOrientation.x,3*q_GreenLineOrientation.y,3*q_GreenLineOrientation.z);

	//画红线
	glColor3f(1,0,0);
	glVertex3f(0,0,0);
	glVertex3f(3*q_RedLineOrientation.x,3*q_RedLineOrientation.y,3*q_RedLineOrientation.z);
	
	//画青色线
	glColor3f(0,1,1);
	glVertex3f(0,0,0);
	glVertex3f(3*q_CyanLineOrientation.x,3*q_CyanLineOrientation.y,3*q_CyanLineOrientation.z);

	glEnd();



	//3 end
	cgGLDisableProfile(myCgVertexProfile);
	checkForCgError("disabling vertex profile");
	//2 begin
	cgGLDisableProfile(myCgFragmentProfile);
	checkForCgError("disabling fragment profile");
	//2 end
	glutSwapBuffers();
}
//3 begin
static int direction=1;
static double vel=1;
static void idle(void)
{
	dMyAngle+=vel;
	dt_Red_between_Blue_and_Green+=direction*0.05;
	if(dt_Red_between_Blue_and_Green>1)
		direction=-1;
	else if(dt_Red_between_Blue_and_Green < 0)
		direction=1;
  glutPostRedisplay();
}
//3 end
static void keyboard(unsigned char c,int x,int y)
{
	//3 begin
	static int animating = 0;
	//3 end
	switch(c)
	{
	//3 begin
	case ' ':
		animating = !animating; /* Toggle */
		if (animating) 
		{
		  glutIdleFunc(idle);
		}
		else
		{
		  glutIdleFunc(NULL);
	    }
		break;
	case 'w':
		dt_Cyan_between_Magenta_and_Greeen+=0.01;
		std::cout<<dt_Cyan_between_Magenta_and_Greeen<<std::endl;
		break;
		
	case 's':
		dt_Cyan_between_Magenta_and_Greeen-=0.01;
		std::cout<<dt_Cyan_between_Magenta_and_Greeen<<std::endl;
		break;
	case 'a':
		vel+=0.1;
		cout<<"vel:"<<vel<<endl;
		break;
	case 'd':
		vel-=0.1;
		cout<<"vel:"<<vel<<endl;
		break;
	//3 end
	case 27:
		cgDestroyProgram(myCgVertexProgram);
		cgDestroyContext(myCgContext);
		exit(0);
		break;
	}
}

MyVertex.cg

void MyVertexEntry(float4 position : POSITION,
				   float4 color:COLOR,
                 out float4 oPosition : POSITION,
                 out float4 oColor:COLOR,
             uniform float4x4 modelViewProj)
{
  // Transform position from object space to clip space
  oPosition = mul(modelViewProj, position);
  oColor=color;
}


对应的可执行文件以及源文件请点这里下载


四元组还有对数和指数的概念,我现在也没有研究,等有时间补上.OK大家下个专题再见了得意


flutter 3D动效之欧拉角和四元数 欧拉角是指三个旋转角度,分别为绕X轴旋转的角度、绕Y轴旋转的角度和绕Z轴旋转的角度,表示物体在空间中的位置和方向。而四元数是一种复数形式的数字,由实部和虚部组成,可以用来表示旋转。欧拉角比较直观,易于理解,但是欧拉角存在万向锁问题,即当某一轴旋转角度为90度时,其他两个轴的旋转将变得不可控。而四元数则没有万向锁问题,并且可以实现平滑旋转,因此在计算机图形学和游戏开发中被广泛应用。3、 下载three_dart,在MultiViews2里添加。 阅读详情

相关推荐

Python实现3D建模工具(上)

人类是那么得有创造力,我们创造、发明、设计、生产了一切大自然没有直接给予我们的东西使我们的生活变得更轻松更美好。在过去,我们只能在图纸上进行产品的创造与设计,而现在,有了计算机的帮助,有了CAD(计算机辅助设计)软件,大大节省了我们的精力与时间成本,使我们的工作更高效,能够拥有更多时间去思考设计本身。那么CAD软件是如何写出来的呢?CAD软件种类繁多,但它们有一个共同的特点,就是对三维世界的建模,对三维世界中物体的控制,对三维设计的展示。这,就是本课程要实现的内容了。

全网120W+关注AI拉呱,专注人工智能以及科技前沿! 1827

理解四元组 Understanding Quaternions

翻译自 https://www.3dgep.com/understanding-quaternions/ 四元组 Transformation matrices 在三维空间中,任何一个坐标系可以有一个4*4的转换矩阵表示,其中左上角3*3的矩阵表示旋转矩阵,第四列前三个表示x,y,z坐标。 类似的,任何一个变换也可以表示为这样一个变换矩阵。 复数 不做过多解释 i2=j2=k2=...

zhoujunr1的博客 1万+

CVPR2021 CenterPoint源码解读:从VoxelNet到两阶段优化的完整实现细节

本文深度解析了CVPR 2021 CenterPoint模型的完整实现细节,从VoxelNet体素化、稀疏卷积Backbone,到基于中心点的检测头与两阶段精修机制。文章提供了从环境搭建、数据预处理到核心代码模块(如热力图生成、关键点特征提取与MLP Refiner)的实战指南,并分享了训练策略、多任务损失调优及可视化调试等关键工程实践,助力开发者深入理解并复现这一高效的3D目标检测框架。

linux的博客 473

计算机网络-TCP篇

TCP篇 基本认识 TCP 是⾯向连接的(⼀定是「⼀对⼀」才能连接)、可靠的、基于字节流的传输层通信协议。 RFC 793 是如何定义「连接」的:⽤于保证可靠性和流量控制维护的某些状态信息,这些信息的组合,包括Socket、序列号和窗⼝⼤⼩称为连接。 建⽴⼀个 TCP 连接是需要客户端与服务器端达成上述三个信息的共识。 Socket:由 IP 地址和端⼝号组成 序列号:⽤来解决乱序问题等 窗⼝⼤⼩:⽤来做流量控制 TCP 四元组可以唯⼀的确定⼀个连接,四元组包括如下: 格式 序列

dz45693的专栏 5447

STGCN实战:从零构建PyTorch时空图卷积网络预测城市交通流

本文详细介绍了如何使用PyTorch从零构建时空图卷积网络(STGCN)进行城市交通流预测。通过将交通网络建模为图结构,并融合时间卷积与空间图卷积,STGCN能有效捕捉交通流的时空依赖性。文章提供了从数据预处理、核心模块(TimeBlock与STGCNBlock)搭建、模型训练到实战技巧的完整指南,帮助开发者快速掌握这一前沿的交通速度预测技术。

wasm7browser的博客 252

手把手教你用Python实现双三次插值(附OpenCV对比测试)

本文深入解析了双三次插值算法的数学原理,并提供了从零开始的Python实现教程。通过与OpenCV官方实现的对比测试,详细评估了不同插值算法(包括最邻近差值、双线性插值)在图像质量与计算性能上的差异,帮助开发者掌握高质量图像缩放的核心技术。

weixin_29310605的博客 301

什么是网络四元组?

网络四元组

weixin_47219891的博客 1959

新手也能玩转!用Panosim+MATLAB/Simulink搭建你的第一个智能驾驶仿真场景(保姆级图文)

本文为新手提供了使用Panosim和MATLAB/Simulink搭建智能驾驶仿真场景的详细教程。从环境准备、基础场景创建到仿真模型构建,一步步指导用户完成第一个智能驾驶仿真项目,帮助零基础用户快速上手并体验智能驾驶仿真的乐趣。

weixin_29090089的博客 193

(转)四元组与旋转矩阵

四元组与旋转矩阵 2 推荐 在3D程序中,通常用quaternion来计算3D物体的旋转角度,与Matrix相比,quaternion更加高效,占用的储存空间更小,此外也更便于插值。在数学上,quaternion表示复数w+xi+yj+zk,其中i,j,k都是虚数单位:    i*i = j*j = k*k= -1 i*j = k, j*

随便写写 7518

【WorkBuddy专栏39】零基础也能做小程序——WorkBuddy微信小程序开发完全指南

【WorkBuddy专栏39】零基础也能做小程序——WorkBuddy微信小程序开发完全指南

AI人人懂 3333

高通开发系列 - System之FOTA/DFOTA包制作和升级

高通开发系列 - System之FOTA/DFOTA包制作和升级

fulinux的博客 4236

3D游戏中的数学运用

原创文章如需转载请注明:转载自 脱莫柔Unity3D学习之旅 Unity3D引擎技术交流QQ群:【119706192】本文链接地址: 3D游戏中的数学运用 【01】3D游戏数学简介 总导:游戏中会使用到的数学有:三角学、微积分、物理学、代数学、统计学。 在学习3D游戏编程的时候,对于所需要的基础数学知识有: 矢量、矩阵、四元数、射线、平面、多边形、简单的物理学。

wfziyou的专栏 809

**YOLOv11性能突破:基于YOLOv10-PSA注意力机制的目标检测革命性升级**

购买即可解锁300+YOLO优化文章,并且还有海量深度学习复现项目,价格仅需两杯奶茶的钱,别人有的本专栏也有!

m0_71589036的博客 201

39. 游戏数学基础

 矢量是游戏开发中涉及到的最基本的对象。矢量有多种形式,可以是2D、3D或4D等。3D矢量是一个包含3个浮点数的结构,每个值代表矢量中不同的轴。这些值分别是x、y和z轴,可用于描述三维空间。矢量用于描述3D空间中的方向,它可能也是最常用的数学对象。        矩阵是游戏开发中第二个最常用的数学对象。矩阵主要用于将矢量从一个坐标系转换到另一个坐标系,还可用于旋转和平移。矩阵由浮点数的2D数组组...

weixin_33998125的博客 310

C#【通用方法】字节数组添加、移除、获取的方法类(妙用List<byte>,开发中常用)

C#【通用方法】添加移除字节的方法类(妙用List,开发中常用)

星Yeah 的博客 3363

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

C++3D数学库设计详解 向量篇之美

Preface   为了支持光线追踪的学习,决定写一个3D泛型数学库。   我采用的是windows平台以及C++Template技术      我的库文件组织目录如下   --lvgm   ----test   ------testVec.cpp   ----type_vec   ------lv_vec2.h   ------lv_vec3.h   ------type_...

游戏开发、游戏引擎开发、逆向破解爱好者 1571

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

四元组与旋转矩阵

来源:http://bezier.zhmy.com/archives/2009/156323.html     在3D程序中,通常用quaternion来计算3D物体的旋转角度,与Matrix相比,quaternion更加高效,占用的储存空间更小,此外也更便于插值。在数学上,quaternion表示复数w+xi+yj+zk,其中i,j,k都是虚数单位:  i*i = j*j = k*k= ...

windshg的专栏 365

贝叶斯统计 [韦来生编]

贝叶斯(Bayes)统计是近几十年来迅速发展起来的数理统计的一个重要分支。贝叶斯方法与经典统计方法的主要不同之处是进行统计推断时除了利用样本信息外,还要利用参数的先验信息,因此可以提高统计推断或统计决策的效果。它在经济、金融、生物、医学、自然科学和社会科学等许多领域具有广泛的应用。贝叶斯方法的研究已渗透到了统计学的几乎所有领域。作者在给中国科学技术大学概率论与数理统计专业本科生开设的“数理统计”课程中有一章专门讲授“贝叶斯方法和统计决策理论”,近十年来也给中国科学技术大学概率统计专业研究生开设过几次“贝叶斯分析”课。本书是在对过去讲稿的内容作了适当的增减和调整的基础上完成的。  本书共分六章。第1章是绪论,介绍了贝叶斯统计的若干基本概念,同时对必要的数理统计的基础知识有重点地作了回顾。第二章介绍了确定先验分布的若干可供选择的方法。第三章介绍了几类常见统计模型参数的后验分布的主要结果和计算方法。第四章和第五章分别介绍了“贝叶斯统计推断”和“贝叶斯统计决策”的内容。第六章介绍了贝叶斯统计计算的若干方法,包括蒙特卡洛方法和马尔可夫链蒙特卡洛(MCMC)方法以及相关统计软件的简介。本书的每一章附右大量的例题和习题,书末附有常用的几个表格和部分习题解答供读者查用。  大约可在54学时内讲授本书的第1章至第六章的主要内容,教师可根据学时需要选讲本书第1章至第六章的部分内容。书中标“*”号的章节可略去不讲,留给读者作为阅读材料。第六章例题中的R代码和部分例题的数据文件等可从作者个人主页下载。  作者在编写本书的过程中参考了J.O.Berger教授的《统计决策论及贝叶斯分析》和茆诗松教授编写的《贝叶斯统计》等书中的一些内容,以及《贝叶斯分析》一书中由张伟平博士编写的有关贝叶斯统计计算的一些内容。在此表示衷心感谢。  本书编写准备过程中,中国科学技术大学统计与金融系的几个研究生帮助完成了本书部分中文的录入和排版,作者对他们的辛勤工作表示真诚的感谢。高等教育出版社为本书的出版给予了大力支持。在此一并致谢。

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

41.D3D数学库 && GameProject7

要介绍的引擎中出现的第一个新文件是mathDefines.h头文件。该文件保存了所有的define语句,这些语句是数学库、引擎及游戏都要用到的内容。这些define语句包含了π(圆周率,圆的周长与直径的比值)的定义、平面结果和将度转换成弧度的宏。该文件随着本书的深入而不断扩充,但目前它非常小,只包含几个define语句。程序清单8.30给出了mathDefines.h头文件的内容。 ...

diaoqu4574的博客 147

<泛> C++3D数学库设计详解 向量篇

// 注:本内容为作者原创,禁止在其他网站复述内容以及用于商业盈利,如需引用,请标明出处:http://www.cnblogs.com/lv_anchoret/ Preface   为了支持光线追踪的学习,决定写一个3D泛型数学库。   我采用的是windows平台以及C++Template技术      我的库文件组织目录如下   --lvgm   ----test   -...

weixin_30318645的博客 411

可微分硬件光栅化技术:3D高斯泼溅渲染优化

可微分渲染是计算机图形学与深度学习交叉领域的关键技术,通过将渲染过程转化为可微操作,实现端到端的场景优化与训练。其核心原理在于构建前向渲染与后向梯度传播的完整计算图,其中硬件光栅化技术通过GPU固定管线显著提升3D高斯泼溅等显式表示的渲染效率。在工程实践中,可编程混合技术与混合精度策略的引入,既保留了参数可微性,又实现了3-10倍的性能提升。这类技术特别适用于实时神经渲染、AR场景重建等需要动态优化的应用场景,其中3D高斯泼溅的硬件加速方案通过四元组归约和子组优化,将内存占用降低至传统方法的24%,为实时图

weixin_30715523的博客 332

着色器和效果——2.5 样例应用程序:卡通渲染(下)

2.5 样例应用程序:卡通渲染(下)阅读此文表明您已同意文末的声明2.5.3 轮廓勾勒要完成卡通效果,我们还需要勾勒(outline)轮廓边(silhouette edge)。这比卡通着色复杂一点。2.5.3.1 边的表示法我们将一个网格的一条边表示为一个四元组(从两个三角形构建)——参见图2.5。图 2.5:表示边的四元组我们选择四元组有两个原因:我们可以通过调整

RaymondKing的专栏 4800

[D3D] - DirectX SDK 2006学习笔记5——动画和矩阵变换

来源:http://www.cnblogs.com/fence/archive/2010/03/12/1683918.html  D3D中世界的运动是通过矩阵变化完成的。这里不打算讲数学知识,相关问题请参考计算机图形学书籍。   在D3D中矩阵 变换分为三种:世界变换,观察变换和投影变换。世界变换描述了物体本身的缩放,旋转和平移,也就是物体本身的运动;观察变换描述了一个观察者在场景中的位 置和朝...

weixin_30371469的博客 158

DirectX12 3D 游戏开发与实战第三章内容

变换 学习目标 理解如何使用矩阵表示线性变换和仿射变换 学习对几何体进行缩放、旋转和平移的坐标变换 根据矩阵之间的乘法运算性质,将多个变换矩阵合并为一个单独的净变换矩阵 找寻不同坐标系之间的坐标转换方法,并利用矩阵来表示此坐标变换 熟悉DirectXMath库中专门为构建变换矩阵所提供的相关函数 3.1线性变换 3.1.1定义 如果有一个函数t可以使 t(u + v) = t(u) ...

Lindong2016的博客 618
上一篇: 3D数学之矩阵的各种求逆
下一篇: 3Dshader之膨胀与收缩
seamanj
博客等级 码龄19年 617粉丝 826原创
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值