Appendix a Basic Mathematics for 3D Computer Graphics
Total Page:16
File Type:pdf, Size:1020Kb
Appendix A Basic Mathematics for 3D Computer Graphics A.1 Vector Operations (),, A vector v is a represented as v1 v2 v3 , which has a length and direction. The location of a vector is actually undefined. We can consider it is parallel to the line (),, (),, from origin to a 3D point v. If we use two points A1 A2 A3 and B1 B2 B3 to (),, represent a vector AB, then AB = B1 – A1 B2 – A2 B3 – A3 , which is again parallel (),, to the line from origin to B1 – A1 B2 – A2 B3 – A3 . We can consider a vector as a ray from a starting point to an end point. However, the two points really specify a length and a direction. This vector is equivalent to any other vectors with the same length and direction. A.1.1 The Length and Direction The length of v is a scalar value as follows: 2 2 2 v = v1 ++v2 v3 . (EQ 1) 378 Appendix A The direction of the vector, which can be represented with a unit vector with length equal to one, is: ⎛⎞v1 v2 v3 normalize()v = ⎜⎟--------,,-------- -------- . (EQ 2) ⎝⎠v1 v2 v3 That is, when we normalize a vector, we find its corresponding unit vector. If we consider the vector as a point, then the vector direction is from the origin to that point. A.1.2 Addition and Subtraction (),, (),, If we have two points A1 A2 A3 and B1 B2 B3 to represent two vectors A and B, then you can consider they are vectors from the origin to the points. As we said, any parallel vectors with the same length and direction are equivalent. Therefore, we can move a vector in 3D space as long as it stays parallel. As shown in Fig. A.1, vector addition is just connecting the vectors. That is: (),, A+B = A1 + B1 A2 + B2 A3 + B3 . (EQ 3) A negative vector is just the original vector in reverse direction. Therefore, vector subtraction is just adding a negative vector. (),, A-B = A1 – B1 A2 – B2 A3 – B3 . (EQ 4) B A-B A A A A A+B B -B -B a) vector A and B b) -B c) A + B d) A - B Fig. A.1 Vector addition and subtraction A.1 Vector Operations 379 A.1.3 Dot Product and Cross Product The dot product of two vectors is a scalar value as follows: • AB= A1B1 ++A2B2 A3B3 . (EQ 5) The dot product is also equal to: AB• = ABcosθ , (EQ 6) where θ is the angle between the two vectors. Therefore, given two vectors, we can easily find the angle between the two vectors according to Equation 5 and Equation 6. When the two vectors are unit vectors, their dot product is the cosine of their angle. The cross product of two vectors A and B is a vector perpendicular to the two vectors and has a magnitude equal to the area of the parallelogram generated from the two vectors, as shown Fig. A.2. A×B B B θ θ A A a) vector dot product a) vector cross product Fig. A.2 Vector dot product and cross product The area of the parallelogram is: AB× = ABsinθ . (EQ 7) The direction of the cross product is according to the right-hand rule, which is in the thumb’s direction if our right-hand’s four fingers go from vector A to B. Therefore, the order of the two vectors in the cross product equation matters. The cross product can be calculated by a determinant as follows: 380 Appendix A ijk × AB= A1 A2 A3 , (EQ 8) B1 B2 B3 where (i, j, k) represent (x, y, z) components. That is, × (),, AB= A2B3 – A3B2 A3B1 – A1B3 A1B2 – A2B1 . (EQ 9) Cross products are often used to find a vector that is perpendicular to the two vectors. Also, according to Equation 7 and Equation 9, the cross products are often used to find sine of their angle. A.1.4 Reflection A reflection of vector A around vector N is a vector B as shown in Fig. A.3, which has the same length making the same angle around N. B B N’ N θ N θ θ θ A A Fig. A.3 Vector reflection around a normal vector As we can see, B = N’ - A; (EQ 10) N’ = 2n|A|cosθ. (EQ 11) A.1 Vector Operations 381 where n is the unit vector along N: n = N/|N|, (EQ 12) and cosθ = n•A/|A|. (EQ 13) Putting them all together, B = 2N•A/|N| - A. (EQ 14) Reflection is needed in ray tracing. A.2 Matrix Operations A matrix is represented as A = (ai,j) for i=1,...n rows; j=1,...,m columns as follows: a11 ... a1m A = ... ... ... (EQ 15) an1 ... anm A.2.1 Transpose T The transpose of A = (ai,j) for i=1,...n; j=1,...,m is a matrix A = (aj,i) for i=1,...n; j=1,...,m, which swaps the rows with columns of the original matrix. That is: a11 ... an1 T A = ... ... ... (EQ 16) a1m ... anm 382 Appendix A A.2.2 Addition and Subtraction For two matrices A = (ai,j) and B = (bi,j), A + B = (ai,j + bi,j) and A - B = (ai,j -bi,j) for i=1,...n; j=1,...,m. That is: ()() a11 + b11 ... a1m + b1m AB+ = ... ... ... ; (EQ 17) ()() an1 + bn1 ... anm + bnm ()() a11 – b11 ... a1m – b1m AB– = ... ... ... (EQ 18) ()() an1 – bn1 ... anm – bnm For example, 123 321 ()13+ ()22+ ()31+ 444 456 + 789 ==()47+ ()58+ ()69+ 11 13 15 . (EQ 19) 789 456 ()74+ ()85+ ()96+ 11 13 15 The transpose of two matrices added together is: T T T ()AB+ A += B . (EQ 20) A.2.3 Multiplications If we multiply a matrix A = (ai,j) for i=1,...n; j=1,...,m with a scalar value c, the result is calculated by multiplying every element of A with c: cA = (cai,j) for i=1,...n; j=1,...,m. For example: A.1 Vector Operations 383 321 963 3 789 = 21 24 27 (EQ 21) 456 12 15 18 2 1 1 --- --- 3 3 321 7 8 789 ⁄ 3 = --- --- 3 (EQ 22) 3 3 456 4 5 --- --- 2 3 3 If we multiply two matrices together, it is required that the number of columns of the left matrix is the same as the number of rows of the right matrix. For example, if matrix A = (ai,j) for i=1,...n; j=1,...,m, then matrix B = (bi,j) has to be with i=1,...m; j=1,...,n in order to have the matrix multiplication: () AB = ∑ aik, bkj, (EQ 23) 0kn≤≤ That is: () () ∑ a1k, bk1, ... ∑ a1k, bkm, 1kn≤≤ 1kn≤≤ AB = ... ... ... (EQ 24) () () ∑ ank, bk1, ... ∑ ank, bkm, 1kn≤≤ 1kn≤≤ For example, 384 Appendix A 12 123 ()1615++ ()2818++ 22 28 34 ==. (EQ 25) 456 ()41530++ ()82036++ 49 64 56 As we can see, matrix multiplication is not commutative. In general, AB≠BA. The transpose of two matrices multiplied together is: T T T ()AB = B A . (EQ 26) A.2.4 Square Matrix and Inverse A square matrix is a matrix with the same number of rows and columns: A = (ai,j) for i=1,...n and j=1,...n. An identity matrix I, which is also called a unit matrix, is a square matrix with the main diagonal value equal to one (ai,j = 1) and all other elements equal to zero. Any matrix multiply its identity matrix is the matrix itself: AI = IA = I. For example, for n=3, 100 I3 = 010 . (EQ 27) 001 If AB = I, then B is called the inverse or reciprocal matrix of A, denoted by A-1. A has an inverse, which is called nonsingular or invertible, if and only if the determinant |A|≠0. a a For a 2×2 matrix, A = 11 12 , a21 a22 –1 1 a22 –a12 A = ------ . (EQ 28) A –a21 a11 A.1 Vector Operations 385 There are several methods to calculate the inverse, but they are numerically complex. The numerical complexity of matrix inversions is several orders of more calculations than matrix multiplications. In graphics, matrix inverse is implemented for transforming the normals and other applications. Appendix B Graphics Software Tools Appendix Objectives: • Provide a comprehensive list of graphics software tools. • Categorize graphics tools according to their applications. Many tools come with multiple functions. We put a primary category name behind a tool name in the alphabetic index, and put a tool name into multiple categories in the categorized index according to its functions. B.1 Graphics Tools Listed by Categories We have no intention of rating any of the tools. Many tools in the same category are not necessarily of the same quality or at the same capacity level. For example, a software tool may be just a simple function of another powerful package, but it may be free. Low-level Graphics Libraries 1. Coin3D - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 431 2. DirectX/Direct3D - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 440 3. GKS-3D - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 456 4. Jogl - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 472 5. Mesa - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 487 6. OpenGL - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 501 7. OpenGL For Java (GL4Java, Maps OpenGL and GLU APIs to Java) - - - - - - - - - 501 8. QuickDraw3D - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 514 9. Tao Framework - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 533 388 Appendix B 10. XGL - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 559 Visualization Tools 1. 3D Grapher (Illustrates and solves mathematical equations in 2D and 3D) - - - - - - 402 2. 3D Studio VIZ (Architectural and industrial designs and concepts) - - - - - - - - - - - 404 3. 3DField (Elevation data visualization) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 406 4. 3DVIEWNIX (Image, volume, soft tissue display, kinematic analysis) - - - - - - - - 407 5. Amira (Medicine, biology, chemistry, physics, or engineering data) - - - - - - - - - - 415 6. Analyze (MRI, CT, PET, and SPECT) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 416 7.