CPT205 W2

This’s the note of CPT205 W2.


The topics for this week:

  1. Computer representation of objects
  2. Cartesian co-ordinate system
  3. Points, lines and angles
  4. Trigonometry 三角函数
  5. Vectors (unit vector) and vector calculations (addition, subtraction, scaling, dot product, cross product) 矢量和矢量计算
  6. Matrices (dimension, transpose, square/symmetric/identity, inverse) and matrix calculations (addition, subtraction, multiplication) 矩阵和矩阵计算

因为矩阵的知识快忘光了,所以矩阵的部分写的比较多。


Lecture

Computer representation of objects

Computer representation of objects


Cartesian co-ordinate system

都是笛卡尔平面直角坐标系的知识,不会的建议重开。


Points, lines and angles

同上。


Trigonometry

同上。


Vectors

同上。


Matrices

  • Techniques for applying transformations use matrices. 应用变换的技术使用矩阵。
  • A matrix is simply a set of numbers arranged in a rectangular format. 矩阵是一组按矩形形式排列的数字。
  • Each number is known as an element. 每个数字都是一个元素。
  • Capital letters are used to represent a matrix. 用大写字母表示矩阵。
  • Bold letters when printed (M), or underlined when written. 打印时加粗或下划线。
  • A matrix has dimensions that refer to the number of rows and the number of columns it has. 矩阵的维数指的是它的行数和列数

Dimensions of matrices

The dimensions of Matrix are (x * y). x is the number of rows in matrix and y is the columns.
$$
\begin{bmatrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
\end{bmatrix}
$$
The dimensions of this matrix are (2*3).

Transpose matrix

When a matrix is rewritten so that its rows and columns are interchanged, then the resulting matrix is called the transpose of the original. 当一个矩阵被改写使它的行和列互换时,得到的矩阵叫做原矩阵的转置。
The original A:
$$
\begin{bmatrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
\end{bmatrix}
$$
The transpose matrix of A:
$$
\begin{bmatrix}
1 & 4 \\
2 & 5 \\
3 & 6 \\
\end{bmatrix}
$$

Square and symmetric matrices

  • A square matrix is matrix where the number of rows equals the number of columns. 行列数量相同的是方阵。
  • A symmetric matrix is a square matrix where the rows and columns are such that its transponse is the same as the original matrix. 对角线对称的方阵是对称矩阵。

Identity matrices

An identity matrix, I is a square matrix with zeros everywhere except its diagonal elements which have a value of 1. 单位矩阵就是对角线是1,剩下的都是0的方阵。


Adding matrices

  • Matrices A and B may be added if they have the same dimensions.
  • That is, the corresponding elements may be added to yield a resulting matrix.
  • The sum is commutative, i.e. A + B = B + A 加法交换律
    Adding matrices

Subtracting matrices

Matrix B may be subtracted from matrix A if they have the same dimensions, i.e. the corresponding elements of B may be subtracted from those of A to yield a resulting matrix.
Subtracting matrices
The result is not commutative. Reversing the order of the matrices yields different results, i.e. A - B ≠ B -A ⚠️减法🈚️交换律!

Multiplying matrices

  • By a constant
    constant * matrices
  • By a matrix - The rule for multiplying one matrix to another is simple: if the number of columns in the first matrix is the same as the number of rows in the second matrix, the multiplication can be done. 也就是必须要是(x * y)&(y * z),计算结果是(x * z)。
    Multiplying matrices
    矩阵乘法计算过程图示

Matrix multiplication is not commutative. Reversing the order of the matrices yields different results. ⚠️矩阵的乘法也是没有交换律的!交换相乘的两个矩阵的位置会产生不同的结果。

Inverse matrices

If two matrices A and B, when multiplieid together, results in an indentity matrix I, then matrix A is the inverse of matrix B and vice versa, i.e.
$$A * B = B * A = I$$
$$A = B^{-1} and B = A^{-1}$$
两个矩阵相乘是一个单位矩阵那这两个矩阵就是逆矩阵。


Lab

The tutorial explains the C/C++ basics that will be used in CPT205 Computer Graphics.
跟着lab做问题不大,注意一个cpp的project中只有可以有一个main方法,这是和py不一样的地方。
学校给的那个lab代码需要引入math才可以正常操作。
引入库的时候需要手动输入,复制粘贴的时候会出现无法读取的问题 #include <GL/freeglut.h>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#define FREEGLUT_STATIC 

#include <GL/freeglut.h>
#include <math.h>
void define_to_OpenGL();

///////////////////////////////////
int main(int argc, char** argv)
{
glutInit(&argc,argv);
// Task 2
glutInitWindowSize(600, 400); // 整个window的大小
glutInitWindowPosition(50, 50); // window的左上角对于屏幕左上角的坐标
glutCreateWindow("Graphics Primitives"); // 初始化一个窗口
glutDisplayFunc(define_to_OpenGL);
glutMainLoop(); // 实现循环
}
///////////////////////////////////
void define_to_OpenGL()
{
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT);

// The stuff to appear on screen goes here
// Task 2 Set the Dimensions
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-100,500,-200,200); // window的原点设定,因为window是600*400,所以这里的x1x2y1y2分别代表了左下角的点和右上角的点。

// Task 3 Draw the Axes
glLineWidth(1.0);
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINES);
glVertex2f(0.0,0.0); // start location
glVertex2f(450.0,0.0); // end location
glVertex2f(0.0,-150.0); // start location
glVertex2f(0.0,150.0); // end location
glEnd();

// Task 4 Draw a Dot at the Origin
glPointSize(10);
glColor3f(1.0,0.0,1.0);
glBegin(GL_POINTS);
glVertex2f(0.0,0.0);
glEnd();

// Task 5 Plot a Sine Wave
// draw a sine wave
int i;
float x,y;
glColor3f(0.0,0.0,1.0);
glPointSize(1);
glBegin(GL_POINTS);
for(i=0;i<361;i=i+1)
{
x = (float)i;
y = 100.0 * sin(i*(2*3.14/360.0)); //角度360转弧度2Π,sin函数里面放的是弧度
glVertex2f(x,y);
}
glEnd();

// Tasks 6 Draw a Triangle
// Tasks 7 Draw A Multi-coloured Triangle
// Tasks 8 Draw a Single-coloured Triangle
glShadeModel(GL_FLAT); //turn off the smoothing capability
glBegin(GL_TRIANGLES);
glColor3f(1, 0, 0);
glVertex2f( -50, 50 );
glColor3f(0, 1, 0);
glVertex2f( -50, 0 );
glColor3f(0, 0, 1);
glVertex2f( 0, 0 );
glEnd();

glFlush(); // 这两个是让图像显示到屏幕上
}

References

  1. XJTLU CPT205 slides (Week2)
作者

Felix Chen

发布于

2021-09-20

更新于

2021-09-22

许可协议

评论