[Study Notes] Computer Graphics (1)

Computer Graphics Study Notes (1)

What is Computer Graphics

The main research content of computer graphics is to study how to represent graphics in computers, as well as the related principles and algorithms of computing, processing and displaying graphics using computers.

What is a good picture?

A simple criterion for judging from a technical level: directly look at whether the picture is "bright" enough. It reflects whether the global illumination in graphics is done well. If the lighting is done well, the picture will be bright, otherwise it will be dark.

Linear Algebra

vector

The two basic contents of a vector, direction and length.

1. Unit vector

A vector of length one is called a unit vector.

a ^ \hat{a} a^ is the unit vector
a ^ = a ⃗ ∣ a ⃗ ∣ \hat{a}= { {\vec{a}} \over {|\vec{a}|}}a^=a a

2. Sum of vectors

a ⃗ \vec{a}a ( xa , ya ) (x_a,y_a)(xa,ya)

b ⃗ \vec{b}b is ( xb , yb ) (x_b,y_b)(xb,yb)

a ⃗ + b ⃗ = ( x a + x b , y a + y b ) \vec{a}+\vec{b}=(x_a+x_b,y_a+y_b) a +b =(xa+xb,ya+yb)

3. Vector dot multiplication

a ⃗ \vec{a}a ( xa , ya , za ) (x_a,y_a,z_a)(xa,ya,za)
b ⃗ \vec{b}b ( x b , y b , z b ) (x_b,y_b,z_b) (xb,yb,zb)

a ⃗ \vec{a}a and b ⃗ \vec{b}b The dot product is expressed as:
a ⃗ ⋅ b ⃗ = cos θ ∣ a ⃗ ∣ ∣ b ⃗ ∣ {\vec{a}\cdot\vec{b}=cos \theta|\vec{a}||\vec{b }|}a b =cosθa ∣∣b ∣if a ⃗ \vec{a
}a and b ⃗ \vec{b}b Both are unit vectors, namely a ^ \hat{a}a^ b ^ \hat{b} b^
cos θ = a ^ ⋅ b ^ cos \theta=\hat{a}\cdot\hat{b}cosθ=a^b^
a ⃗ \vec{a}a and b ⃗ \vec{b}b 点乘还可以表示为:
a ⃗ ⋅ b ⃗ = a ⃗ T b ⃗ = ( x a y a z a ) ( x b y b z b ) = x a x b + y a y b + z a z b {\vec{a}\cdot\vec{b}=\vec{a}^T\vec{b}= \begin{pmatrix} x_a&y_a&z_a\\ \end{pmatrix}} \begin{pmatrix} x_b\\ y_b\\ z_b\\ \end{pmatrix} =x_ax_b+y_ay_b+z_az_b a b =a Tb =(xayaza) xbybzb =xaxb+yayb+zazb
The role of dot multiplication

  1. find angle

    The two vectors are normalized to a unit vector, and the dot product of the unit vector is the cosine of the angle.

    Right now:

cos θ = a^⋅b^cos \theta=\hat{a}\cdot\hat{b}cosθ=a^b^
​ Add the cosine law and derivation process:

​ 余弦定理公式:
cos θ = ∣ AC ⃗ ∣ 2 + ∣ AB ⃗ ∣ 2 − ∣ BC ⃗ ∣ 2 2 ∣ AC ⃗ ∣ ∣ AB ⃗ ∣ cos \theta={ {|\vec{AC}|^2 + |\vec{AB}|^2-|\vec{BC}|^2}\over{2|\vec{AC}||\vec{AB}|}}cosθ=2∣AC ∣∣AB AC 2+AB 2BC 2
​ Cosine law derivation process:

BC ⃗ = AC ⃗ − AB ⃗ BC ⃗ 2 = ( AC ⃗ − AB ⃗ ) 2 BC ⃗ TBC ⃗ = ( AC ⃗ − AB ⃗ ) T ( AC ⃗ − AB ⃗ ) ∣ BC ⃗ ⃗ 2 = AC ⃗ TAC ⃗ − 2 AC ⃗ ⋅ AB ⃗ + AB ⃗ TAB ⃗ ∣ BC ⃗ ∣ 2 = ∣ AC ⃗ ∣ 2 − 2 AC ⃗ ⋅ AB ⃗ + ∣ AB ⃗ ∣ 2 ∣ BC ⃗ ∣ 2 = ∣ AC ⃗ ∣ 2 − 2 AC ⃗ ⃗ ∣ 2 θ ∣ AC ⃗ ∣ ∣ AB ⃗ ∣ + ∣ AB ⃗ ∣ 2 cos θ = ∣ AC ⃗ ∣ 2 + ∣ AB ⃗ ∣ 2 − ∣ BC ⃗ ∣ 2 2 ∣ AC ⃗ ∣ ∣ AB ⃗ ∣ \vec{BC}= \vec{AC}-\vec{AB} \\ \vec{BC}^2=(\vec{AC}}\vec{AB})^2 \\ \vec{BC}^T\vec{BC} =(\vec{AC}-\vec{AB})^T(\vec{AC}-\vec{AB}) \\ |\vec{BC}|^2=\vec{AC}^T\vec {AC}-2\vec{AC}\cdot\vec{AB}+\vec{AB}^T\vec{AB} \\ |\vec{BC}|^2=|\vec{AC}|^ 2-2\vec{AC}\cdot\vec{AB}+|\vec{AB}|^2 \\ |\vec{BC}|^2=|\vec{AC}|^2-2cos \theta |\vec{AC}||\vec{AB}|+|\vec{AB}|^2 \\ cos \theta={ {| \vec{AC}|^2+|\vec{AB}|^ 2-|\vec{BC}|^2}\over{2|\vec{AC}||\vec{AB}|}}BC =AC AB BC 2=(AC AB )2BC TBC =(AC AB )T(AC AB )BC 2=AC TAC 2AC AB +AB TAB BC 2=AC 22AC AB +AB 2BC 2=AC 22cosθAC ∣∣AB +AB 2cosθ=2∣AC ∣∣AB AC 2+AB 2BC 2
​ The law of cosines can also be derived by dot product of vectors

  1. Find the projection

    AB ⃗ \vec{AB}AB to AC ⃗ \vec{AC}AC The projection AD ⃗ \vec{AD}AD

    A C ^ \hat{AC} AC^ isAB ⃗ \vec{AB}AB the unit vector of

    ∣ AD ⃗ ∣ = ∣ AB ⃗ ∣ cos θ |\vec{AD}|=|\vec{AB}|cos\thetaAD =AB cosθ

    A D ⃗ = A C ^ ∣ A D ⃗ ∣ \vec{AD}=\hat{AC}|\vec{AD}| AD =AC^AD

  2. approach and front

    The distribution of cos values ​​from 0° to 180°

    [External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-egZWC9gH-1681284850478)(https://songimghost.oss-cn-nanjing.aliyuncs.com/img/desmos -graph1.png)]

    AB ⃗ \vec{AB}AB The closer to AC ⃗ \vec{AC}AC , when θ is about small, cos θ cos\thetaThe closer the cos θ is to 1

    AB ⃗ \vec{AB}AB A C ⃗ \vec{AC} AC When the direction is opposite, θ is greater than 90°, cos θ cos\thetacos θ is a negative value, and the closer it is to -1

Four, vector cross multiplication

In a right-handed coordinate system: AD ⃗ = AB ⃗ × AC ⃗ \vec{AD}=\vec{AB} \times \vec{AC}AD =AB ×AC

AD ⃗ \vec{AD}AD Perpendicular to AC ⃗ \vec{AC}AC
AD ⃗ \vec{AD}AD perpendicular to AB ⃗ \vec{AB}AB

∣ AD ⃗ ∣ = sin θ ∣ AB ⃗ ∣ ∣ AC ⃗ ∣ |\vec{AD}|=sin\theta|\vec{AB}||\vec{AC}|AD =sinθAB ∣∣AC

official:

a ⃗ = ( x a , y a , z a ) \vec{a}=(x_a,y_a,z_a) a =(xa,ya,za)

b ⃗ = ( x b , y b , z b ) \vec{b}=(x_b,y_b,z_b) b =(xb,yb,zb)

a ⃗ × b ⃗ = ( 0 , − z a , y a z a , 0 , − x a − y a , x a , 0 ) ( x b y b z b ) = ( y a z b − y b z a z a x b − x a z b x a y b − y a x b ) \vec{a}\times\vec{b}=\begin{pmatrix}0,-z_a,y_a\\z_a, 0 ,-x_a\\-y_a,x_a,0 \end{pmatrix}\begin{pmatrix}x_b\\y_b\\z_b\end{pmatrix}=\begin{pmatrix}y_az_b-y_bz_a\\z_ax_b-x_az_b\\x_ay_b-y_ax_b \end{pmatrix} a ×b = 0,za,yaza,0,xaya,xa,0 xbybzb = yazbybzazaxbxazbxaybyaxb

The role of cross product

  1. Judging left and right

    In a left-handed coordinate system, b ⃗ × a ⃗ \vec{b}\times\vec{a}b ×a And the z axis is a positive value, indicating that b ⃗ \vec{b}b a ⃗ \vec{a}a clockwise direction.

  2. Judging inside and outside

    ∵ ( C A ⃗ × C D ⃗ ) ⋅ ( A B ⃗ × A D ⃗ ) \because(\vec{CA}\times\vec{CD} )\cdot(\vec{AB}\times\vec{AD}) (CA ×CD )(AB ×AD ) has a positive z-axis

    ∵ ( A B ⃗ × A D ⃗ ) ⋅ ( B C ⃗ × B D ⃗ ) \because (\vec{AB}\times\vec{AD} )\cdot(\vec{BC}\times\vec{BD}) (AB ×AD )(BC ×BD ) has a positive z-axis

    ∴ \therefore Point D is in the middle of ABC

Coordinate system definition

Coordinate decomposition
∣ u ⃗ ∣ = ∣ v ⃗ ∣ = ∣ w ⃗ ∣ = 1 The three vectors are all unit vectors u ⃗ ⋅ v ⃗ = v ⃗ ⋅ w ⃗ = w ⃗ ⋅ u ⃗ = 0 The three vectors are in pairs The angles are all 90 ° w ⃗ = u ⃗ × v ⃗ The vector w ⃗ is perpendicular to the plane p formed by the vectors u ⃗ and v ⃗ ⃗ = ( ( p ⃗ ⋅ u ⃗ ) u ⃗ ( p ⃗ ⋅ v ⃗ ) v ⃗ ( p ⃗ ⋅ w ⃗ ) w ⃗ ) The components of the world coordinate system vector on the uvw coordinates|\vec{u}|=|\vec{v}|=|\vec{w}|=1\\ \\Three Vectors are unit vectors\\~ \\\vec{u}\cdot\vec{v}=\vec{v}\cdot\vec{w}=\vec{w}\cdot\vec{u}=0 \\ \\The angle between two of the three vectors is 90°\\ \\~\\ \vec{w}=\vec{u}\times\vec{v} \\vector\vec{w} is perpendicular to The plane \\~\\ \vec{p}=\begin{pmatrix}(\vec{p}\cdot\vec{u})\vec{u} composed of vectors \vec{u} and \vec{v} \\(\vec{p}\cdot\vec{v})\vec{v}\\(\vec{p}\cdot\vec{w})\vec{w}\end{pmatrix} \\world The component of the coordinate system vector on the uvw coordinateu =v =w =1All three vectors are unit vectors u v =v w =w u =0The angle between two of the three vectors is 90° w =u ×v vectorw perpendicular to the vectoru andv composed of planes p = (p u )u (p v )v (p w )w The component of the world coordinate system vector on the uv w coordinate

matrix

identity matrix

( 1 , 0 , 0 , 0 0 , 1 , 0 , 0 0 , 0 , 1 , 0 0 , 0 , 0 , 1 ) \begin{pmatrix}1,0,0,0\\0,1,0,0\\0,0,1,0\\0,0,0,1\end{pmatrix} 1,0,0,00,1,0,00,0,1,00,0,0,1

matrix product

( a 00 , a 01 , a 02 , a 03 a 10 , a 11 . a 12 , a 13 a 20 , a 21 , a 22 , a 23 a 30 , a 31 , a 32 , a 33 ) × ( b 00 , b 01 , b 02 , b 03 b 10 , b 11 . b 12 , b 13 b 20 , b 21 , b 22 , b 23 b 30 , b 31 , b 32 , b 33 ) = ( c 00 , c 01 , c 02 , c 03 c 10 , c 11 . c 12 , c 13 c 20 , c 21 , c 22 , c 23 c 30 , c 31 , c 32 , c 33 )                                        ( b 00 , b 01 , b 02 , b 03 b 10 , b 11 . b 12 , b 13 b 20 , b 21 , b 22 , b 23 b 30 , b 31 , b 32 , b 33 ) ( a 00 , a 01 , a 02 , a 03 a 10 , a 11 . a 12 , a 13 a 20 , a 21 , a 22 , a 23 a 30 , a 31 , a 32 , a 33 ) ( c 00 , c 01 , c 02 , c 03 c 10 , c 11 . c 12 , c 13 c 20 , c 21 , c 22 , c 23 c 30 , c 31 , c 32 , c 33 )   c 00 = a 00 b 00 + a 01 b 10 + a 02 b 20 + a 03 b 30 c 01 = a 00 b 01 + a 01 b 11 + a 02 b 21 + a 03 b 31 . . \begin{pmatrix}a_{00},a_{01},a_{02},a_{03}\\a_{10},a_{11}.a_{12},a_{13}\\a_{20},a_{21},a_{22},a_{23}\\a_{30},a_{31},a_{32},a_{33}\end{pmatrix}\times\begin{pmatrix}b_{00},b_{01},b_{02},b_{03}\\b_{10},b_{11}.b_{12},b_{13}\\b_{20},b_{21},b_{22},b_{23}\\b_{30},b_{31},b_{32},b_{33}\end{pmatrix}=\begin{pmatrix}c_{00},c_{01},c_{02},c_{03}\\c_{10},c_{11}.c_{12},c_{13}\\c_{20},c_{21},c_{22},c_{23}\\c_{30},c_{31},c_{32},c_{33}\end{pmatrix}\\~\\ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\begin{pmatrix}b_{00},b_{01},b_{02},b_{03}\\b_{10},b_{11}.b_{12},b_{13}\\b_{20},b_{21},b_{22},b_{23}\\b_{30},b_{31},b_{32},b_{33}\end{pmatrix}\\\begin{pmatrix}a_{00},a_{01},a_{02},a_{03}\\a_{10},a_{11}.a_{12},a_{13}\\a_{20},a_{21},a_{22},a_{23}\\a_{30},a_{31},a_{32},a_{33}\end{pmatrix}\begin{pmatrix}c_{00},c_{01},c_{02},c_{03}\\c_{10},c_{11}.c_{12},c_{13}\\c_{20},c_{21},c_{22},c_{23}\\c_{30},c_{31},c_{32},c_{33}\end{pmatrix}\\~\\ c_{00}=a_{00}b_{00}+a_{01}b_{10}+a_{02}b_{20}+a_{03}b_{30}\\c_{01}=a_{00}b_{01}+a_{01}b_{11}+a_{02}b_{21}+a_{03}b_{31}\\.\\. a00,a01,a02,a03a10,a11.a12,a13a20,a21,a22,a23a30,a31,a32,a33 × b00,b01,b02,b03b10,b11.b12,b13b20,b21,b22,b23b30,b31,b32,b33 = c00,c01,c02,c03c10,c11.c12,c13c20,c21,c22,c23c30,c31,c32,c33                                       b00,b01,b02,b03b10,b11.b12,b13b20,b21,b22,b23b30,b31,b32,b33 a00,a01,a02,a03a10,a11.a12,a13a20,a21,a22,a23a30,a31,a32,a33 c00,c01,c02,c03c10,c11.c12,c13c20,c21,c22,c23c30,c31,c32,c33  c00=a00b00+a01b10+a02b20+a03b30c01=a00b01+a01b11+a02b21+a03b31..

c c xxof the c matrixline x , line yyy c x y c_{xy} cxyequal to aaThe xxth of a matrixrow x andbbThe yyth of the b matrixThe y columns are multiplied and added.

matrix multiplication vector

( a 00 , a 01 , a 02 , a 03 a 10 , a 11 . a 12 , a 13 a 20 , a 21 , a 22 , a 23 a 30 , a 31 , a 32 , a 33 ) ( b 00 b 10 b 20 0 ) = ( a 00 b 00 + a 01 b 10 + a 02 b 20 + 0 a 10 b 00 + a 11 b 10 + a 12 b 20 + 0 a 20 b 00 + a 21 b 10 + a 22 b 20 + 0 a 30 b 00 + a 31 b 10 + a 32 b 20 + 0 ) \begin{pmatrix}a_{00},a_{01},a_{02},a_{03}\\a_{10},a_{11}.a_{12},a_{13}\\a_{20},a_{21},a_{22},a_{23}\\a_{30},a_{31},a_{32},a_{33}\end{pmatrix}\begin{pmatrix}b_{00}\\b_{10}\\b_{20}\\0\end{pmatrix}=\begin{pmatrix}a_{00}b_{00}+a_{01}b_{10}+a_{02}b_{20}+0\\a_{10}b_{00}+a_{11}b_{10}+a_{12}b_{20}+0\\a_{20}b_{00}+a_{21}b_{10}+a_{22}b_{20}+0\\a_{30}b_{00}+a_{31}b_{10}+a_{32}b_{20}+0\end{pmatrix} a00,a01,a02,a03a10,a11.a12,a13a20,a21,a22,a23a30,a31,a32,a33 b00b10b200 = a00b00+a01b10+a02b20+0a10b00+a11b10+a12b20+0a20b00+a21b10+a22b20+0a30b00+a31b10+a32b20+0

matrix transformation

scaling matrix
( S 00 , 0 , 0 , 0 0 , S 11 , 0 , 0 0 , 0 , S 22 , 0 0 , 0 , 0 , 1 ) \begin{pmatrix}S_{00},~~0,~ ~0,~~0\\~0,S_{11},~~0,~~0\\~0,~~0,S_{22},~~0\\~~0,~~0, ~~0,~~1\end{pmatrix} S00,  0,  0,  0 0,S11,  0,  0 0,  0,S22,  0  0,  0,  0,  1
Translation matrix
( 0 , 0 , 0 , T 04 0 , 0 , 0 , T 14 0 , 0 , 0 , T 24 0 , 0 , 0 , 1 ) \begin{pmatrix}~~0,~~0,~~ 0,~~T_{04}\\~~0,~~0,~~0,~~T_{14}\\~~0,~~0,~~0,~~T_{24}\\ ~~0,~~0,~~0,~~1\end{pmatrix}   0,  0,  0,  T04  0,  0,  0,  T14  0,  0,  0,  T24  0,  0,  0,  1
rotation matrix

Matrix transpose

( 1 ,    2 3 ,    4 5 ,    6 7 ,    8 ) T = ( 1 ,    3 ,    5 ,    7 2 ,    4 ,    6 ,    8 ) \begin{pmatrix}1,~~2\\3,~~4\\5,~~6\\7,~~8\end{pmatrix}^T=\begin{pmatrix}1,~~3,~~5,~~7\\2,~~4,~~6,~~8\end{pmatrix} 1,  23,  45,  67,  8 T=(1,  3,  5,  72,  4,  6,  8)

Guess you like

Origin blog.csdn.net/dxs1990/article/details/130108702