630 likes | 645 Views
2IV60 Computer Graphics Basic Math for CG. Jack van Wijk TU/e. Overview. Co ordinates, points, vectors Matrices. H&B A-1. n D Space. n D Space: n (typically) n : number of dimensions Examples: 1D space: time, along a line or curve 2D space: plane, sphere
E N D
2IV60 Computer GraphicsBasic Math for CG Jack van Wijk TU/e
Overview • Coordinates, points, vectors • Matrices H&B A-1
nD Space nD Space: n (typically) n : number of dimensions Examples: • 1D space: time, along a line or curve • 2D space: plane, sphere • 3D space: the world we live in • 4D space: 3D + time H&B A-2
Coordinates 2D Cartesian coordinates: x y (x,y) (x,y) y x Standard Screen (output, input) H&B A-1
Polar coordinates y (x,y) r x H&B A-1
3D coordinates 1 3D Cartesian coordinates: (x,y,z) z (x,y,z) z x y x y Right-handed Left-handed H&B A-1
3D coordinates 2 3D Cartesian coordinates: (x,y,z) (x,y,z) z (middle) z (middle) y (index) x (thumb) x (thumb) y (index) Right-handed Left-handed H&B A-1
3D coordinates 3 Cylinder coordinates: (x,y,z) z y x H&B A-1
3D coordinates 4 Spherical coordinates: (x,y,z) z f r y x H&B A-1
Points • Point: position in nD space • Notation: P (H&B), also P, p, p en p • (x,y,z) (H&B), also (x1, x2, x3), (Px, Py, Pz), (r, , z), ( r, , ), … H&B A-2
Vectors 1 • Vector: • “arrow” • multiple interpretations (displacement, velocity, force, …) • has a magnitude and direction • has no position • Notation: V (H&B), also V, v, v en v • (Vx, Vy, Vz) (H&B), also (x, y, z), (x1, x2, x3) H&B A-2
Vectors 2 y P2 y2 P1 y1 V: directed line segment, or difference between two points x x1 x2 H&B A-2
Vectors 3 Length of a vector: H&B A-2
Vectors 4 Direction of a vector: Direction angles. Unit vector V : Magnitude info is removed, direction is kept. z g b y x a H&B A-2
Vector addition Add components, put vector head to tail y y W V+W W V V x x H&B A-2
Scalar multiplication of vector Multiplication components with scalar s y y 2V V x x H&B A-2
Combining vector operations Infinite line through P with direction V: L(t) = P + Vt, t V y P t x t : parameter along line t [a, b]: line segment H&B A-2
Vector multiplication 1 Scalar product or dot product: Product of parallel components, gives 1 real value W V q |W| cos q |V| H&B A-2
Vector multiplication 2 Scalar product: H&B A-2
Vector multiplication 3 Vector product or cross product: gives a vector (in 3D) n perpendicular to V and W VW W q n V H&B A-2
Vector multiplication 5 Scalar product: H&B A-2
Vector multiplication 6 Scalar product: • scalar • Test if vectors are perpendicular • cos • project,… Vector product: • vector • Get a vector perpendicular to two given vectors • sin • surface area,… H&B A-2
Exercise 1 • Given a point P. • Requested: Reflect a point Q with respect to P. Q W = P – Q Q’ = Q + 2W = 2P – Q or: = P + (P – Q ) W P y W Q’ x We don’t need coordinates!
Exercise 1 • Given a point P. • Requested: Reflect a point Q with respect to P. Q Alternative P is halfway Q and Q’: P = (Q + Q’)/2 2P = Q + Q’ Q’ = 2P – Q P Q’
Exercise 2 • Given a line L: L(t) = P + Vt . • Requested: Reflect a point Q with respect to L. We know: Q’ = Q + 2 W W = L(t) – Q W. V = 0 Q W L(t) V y P W Q’ t x
Exercise 2 We know: L(t) = P + Vt Q’ = Q + 2 W W = L(t) – Q W. V = 0 Substitute to get t: (L(t) – Q).V = 0 (P + Vt–Q).V = 0 V.V t+ (P –Q).V = 0 t = ((Q –P).V) / (V.V) Then: Q’ = Q + 2 (P + Vt – Q) = 2P – Q + 2V((Q –P).V / V.V)
Steps to be made • Write down what you know • Eliminate, substitute, etc. to get he result • Check the result • Does it make sense? • Is there a simpler derivation?
Exercise 3 • Given a triangle with vertices P, Q en R,where the angle PQR is perpendicular. • Requested: Rotate the triangle around the line PQ over an angle a . What is the new position R’ of R? P Q R’ R
Circle in space y C() C() C() = (r cos , r sin , 0) = (0,0,0) + r cos (1,0,0) + r sin (0,1,0) = P + r cos A + r sin B r B B A P x P A |A|=1, |B|=1, A.B = 0
Exercise 3 A = (R – Q) / |R –Q| B = (R – Q)(P– Q) / | (R – Q)(P– Q) | R’ = Q + |R –Q| cos A + |R –Q| sin B P B Q R’ A R
Use: • Scalar product, cross product • coordinate independent definitions • vector algebra Don’t use: • arccos, arcsin • y = f(x)
Very short intro to Linear Algebra System of linear equations: Such systems occur in many, many applications. They are studied in Linear Algebra. H&B A-5
Very short intro to Linear Algebra System of linear equations: Typical questions: • Given u, v, w, what are x, y, z? • Can we find a unique solution? H&B A-5
Very short intro to Linear Algebra System of linear equations: Crucial in computer graphics: • Transforming geometric objects • Change of coordinates H&B A-5
Example transformation y P: (x,y) x y’ P’ V U y x x’ H&B A-5
What is a matrix? Matrix: • Mathematical objects with operations Matrix in computer graphics: • Defines a coordinate frame • Defines a transformation • Handy tool for manipulating transformations H&B A-5
Matrix Matrix: rectangular array of elements Element: quantity (value, expression, function, …) Examples: H&B A-5
Matrix r c matrix: r rows, c columns mij: element at row i and column j. H&B A-5
Matrix r c matrix: r rows, c columns mij: element at row i and column j. r c elements H&B A-5
Matrix r c matrix: r rows, c columns mij: element at row i and column j. c columns H&B A-5
Matrix r c matrix: r rows, c columns mij: element at row i and column j. r rows H&B A-5
Matrix Column vector: matrix with c =1 Used for vectors (and points) Row vector: matrix with r =1 Scalar: matrix with r=1and c=1 H&B A-5
Matrix Matrix as collection of column vectors: W Matrix contains an axis-frame: V U H&B A-5
Operations on matrices • Multiplication with scalar • simple • Addition • simple • Matrix-matrix multiplication • More difficult, but the most important H&B A-5
Scalar Matrix multiplication Matrix M multiplied with scalar s: H&B A-5
Scalar Matrix addition H&B A-5
Scalar Matrix addition • Just add elements pairwise • A and B must have the same number of rows and columns • Generalization of vector and scalar addition H&B A-5
Matrix Matrix multiplication j = 1 ; k i = 2 ; k • cij: dot product of row vector aiand column vector bj • #columns A must be the same as #rows B: n = p • C: m q matrix H&B A-5
Matrix Matrix multiplication Example: i = 3 j = 2 i=3, j=2 H&B A-5
Matrix Matrix multiplication Example: H&B A-5