3. We can rewrite this in matrix form as follows.
3
4. Solution for this in different way
When a point P is rotated about θ, we assume that axis is
rotated about θ.
We assume that rotated x and y-axis about θ is x' and y'-axis.
4
Now, the new point P' is
a point on (cosθ, sinθ) x-
axis, and (-sinθ, cosθ) y-
axis.
So, p'=px(cosθ, sinθ)+py(-
sinθ, cosθ)
5. Caution
When a vector P is in the left side of the matrix, the matrix
must be transposed.
𝑝′ 𝑥
𝑝′ 𝑦
=
𝑐𝑜𝑠𝜃 −𝑠𝑖𝑛𝜃
𝑠𝑖𝑛𝜃 𝑐𝑜𝑠𝜃
𝑝 𝑥
𝑝 𝑦
𝑝′ 𝑥, 𝑝′ 𝑦 = 𝑝 𝑥, 𝑝𝑦
𝑐𝑜𝑠𝜃 𝑠𝑖𝑛𝜃
−𝑠𝑖𝑛𝜃 𝑐𝑜𝑠𝜃
5
9. Linear Transformations
Suppose that we have established a 3D coordinate system C
consisting of an origin and three coordinate axes, in which a
point P has the coordinates x, y, z .
This constitutes a linear transformation from C to C′ and can
be written in matrix form as follows
9
10. Assuming the transformation is invertible, the linear
transformation from C′ to C is given by
We need to combine the 3×3 matrix and translation vector T
into a single 4× 4 transformation matrix.
10
11. Orthogonal Matrices
Most 3×3 matrices arising in computer graphics applications
are orthogonal. An orthogonal matrix is simply one whose
inverse is equal to its transpose.
If the n × n matrix M is orthogonal, then M preserves lengths
and angles.
11
12. Handedness
In three dimensions, a basis for a coordinate system given
by the 3D vectors V1, V2, and V3 possesses a property called
handedness.
A left-handed basis is one for which (V1×V2)⋅V3 < 0.
– in LHS V1×V2=-V3
• Left-handed coordinates on the left
Right-handed coordinates on the right.
12
13. Cross Product
13
The cross product of two three-dimensional vectors, also
known as the vector product, returns a new vector that is
perpendicular to both of the vectors being multiplied
together.
• The cross-product in respect to a left-handed coordinate
system.
14. Coordinate Systems in Direct3D
• Direct3D uses a left-handed coordinate system. If you are
porting an application that is based on a right-handed
coordinate system, you must make two changes to the data
passed to Direct3D.
14
15. Scaling Transforms
To scale a vector P by a factor of a, we simply calculate P′ =
aP. In three dimensions, this operation can also be expressed
as the matrix product.
15
19. We can rewrite this in matrix form as follows.
The matrix Rz(θ ) that performs a rotation through the angle θ
about the z axis is thus given by
19
20. Solution for this in different way
When a point P is rotated about θ, we assume that axis is
rotated about θ.
We assume that rotated x and y-axis about θ is x' and y'-axis.
20
Now, the new point P' is
a point on (cosθ, sinθ) x-
axis, and (-sinθ, cosθ) y-
axis.
So, p'=px(cosθ, sinθ)+py(-
sinθ, cosθ)
21. Caution
When a vector P is in the left side of the matrix, the matrix
must be transposed.
𝑝′ 𝑥
𝑝′ 𝑦
=
𝑐𝑜𝑠𝜃 −𝑠𝑖𝑛𝜃
𝑠𝑖𝑛𝜃 𝑐𝑜𝑠𝜃
𝑝 𝑥
𝑝 𝑦
𝑝′ 𝑥, 𝑝′ 𝑦 = 𝑝 𝑥, 𝑝𝑦
𝑐𝑜𝑠𝜃 𝑠𝑖𝑛𝜃
−𝑠𝑖𝑛𝜃 𝑐𝑜𝑠𝜃
21
22. Similarly, we can derive the following 3×3 matrices Rx(θ ) and
Ry(θ ) that perform rotations through an angle θ about the x
and y axes, respectively:
22
23. Rotation about an Arbitrary Axis
Combining these terms and setting c = cosθ and s = sinθ
gives us the following formula for the matrix RA(θ) that
rotates a vector through an angle θ about the axis A.
23
24. Translation
To transform a point P from one coordinate system to
another, we usually find ourselves performing the operation
P′ =MP + T
where M is some invertible 3×3 matrix and T is a 3D
translation vector.
Fortunately, there is a compact and elegant way to represent
these transforms within a single mathematical entity.
24
25. Translation
P′ =MP + T
Fortunately, there is a compact and elegant way to represent
these transforms within a single mathematical entity.
25
26. 26
P =M-1P' – M-1T
We would therefore expect the inverse of the 4× 4 matrix F to
be
28. When a input vector is at left of a matrix.
When a input vector is at left of a matrix, the translation
vector T will be located at bottom row.
28
𝑴 𝟏𝟏 𝑴 𝟏𝟐 𝑴 𝟏𝟑 𝟎
𝑴 𝟐𝟏 𝑴 𝟐𝟐 𝑴 𝟐𝟑 𝟎
𝑴 𝟑𝟏 𝑴 𝟑𝟐 𝑴 𝟑𝟑 𝟎
𝑻 𝒙 𝑻 𝒚 𝑻 𝒛 𝟏
29. Points and Directions
Unlike points, direction vectors should remain invariant under
translation.
To transform direction vectors using the same 4× 4
transformation matrices that we use to transform points, we
extend direction vectors to four dimensions by setting the w
coordinate to 0.
(x,y,z,w)
(px,py,pz,0)
The upper left 3×3 portion of the matrix to affect the
direction vector.
29
30. Linear Systems
Matrices provide a compact and convenient way to represent
systems of linear equations. For instance, the linear system
given by the equations
can be represented in matrix form as
30
31. The matrix preceding the vector x, y, z of unknowns is called
the coefficient matrix, and the column vector on the right
side of the equals sign is called the constant vector. Linear
systems for which the constant vector is nonzero (like the
example above) are called nonhomogeneous.
Linear systems for which every entry of the constant vector is
zero are called homogeneous.
– The Geometric meaning of homogeneous is all the 3-planes meet at
origin (0,0,0).
31
32. The augmented matrix formed by concatenating the
coefficient matrix and constant vector is
When the linear system is homogeneous, then the matrix cab
be written like this
3 2 −3 0
4 −3 6 0
1
0
0
0
−1
0
0
1
32
33. Homogeneous Matrix
We will use 4x4 matrices to consistently represent translation,
scaling and rotation in 3D space.
In that case a14, a24 and a34 is always zero, when the input
vector is at left of a matrix, this is a Homogeneous Matrix.
33
34. Transform Matrices in Direct3D
You can transform any point (x,y,z) into another point (x', y',
z') by using a 4x4 matrix, as shown in the following equation.
34
35. Translation in Direct3D
The following equation translates the point (x, y, z) to a new
point (x', y', z').
35
D3DXMATRIX Translate(const float dx, const float dy, const float dz) {
D3DXMATRIX ret;
D3DXMatrixIdentity(&ret);
ret(3, 0) = dx;
ret(3, 1) = dy;
ret(3, 2) = dz;
return ret;
} // End of Translate
36. Scaling in Direct3D
The following equation scales the point (x, y, z) by arbitrary
values in the x-, y-, and z-directions to a new point (x', y', z').
36
37. Rotations in Direct3D
The following equation rotates the point (x, y, z) around the x-
axis, producing a new point (x', y', z').
37
D3DXMATRIX* WINAPI D3DXMatrixRotationX
( D3DXMATRIX *pOut, float angle )
{
float sin, cos;
sincosf(angle, &sin, &cos); // Determine sin and cos of angle
pOut->_11 = 1.0f; pOut->_12 = 0.0f; pOut->_13 = 0.0f; pOut->_14 = 0.0f;
pOut->_21 = 0.0f; pOut->_22 = cos; pOut->_23 = sin; pOut->_24 = 0.0f;
pOut->_31 = 0.0f; pOut->_32 = -sin; pOut->_33 = cos; pOut->_34 = 0.0f;
pOut->_41 = 0.0f; pOut->_42 = 0.0f; pOut->_43 = 0.0f; pOut->_44 = 1.0f;
return pOut;
}
38. The following equation rotates the point around the y-axis.
The following equation rotates the point around the z-axis.
38
39. Concatenating Matrices
One advantage of using matrices is that you can combine the
effects of two or more matrices by multiplying them.
This means that, to rotate a model and then translate it to
some location, you don't need to apply two matrices.
In this equation, C is the composite matrix being created, and
M₁ through Mn are the individual matrices.
Use the D3DXMatrixMultiply function to
perform matrix multiplication.
39
49. References
Lengyel, "Mathematics for 3D Game Programming and
Computer Graphics",3rd, 2011
https://msdn.microsoft.com/en-
us/library/windows/desktop/bb206269(v=vs.85).aspx
49
Editor's Notes
Suppose that we have established a 3D coordinate system C consisting of an
origin and three coordinate axes, in which a point P has the coordinates x, y, z .
The values x, y, and z can be thought of as the distances that one must travel
along each of the coordinate axes from the origin in order to reach the point P.
Suppose now that we introduce a second coordinate system C′ in which coordinates
x′, y′, z′ can be expressed as linear functions of coordinates x, y, z in C.
This means that, to rotate a model and then translate it to some location, you don't need to apply two matrices. Instead, you multiply the rotation and translation matrices to produce a composite matrix that contains all their effects.