Download presentation

Presentation is loading. Please wait.

Published bySteven Kearney Modified over 2 years ago

1
1 Points, Vectors, Lines, Spheres and Matrices ©Anthony Steed

2
2 Points Vectors Lines Spheres Matrices 3D transformations as matrices Homogenous co-ordinates Overview

3
3 Basic Maths n In computer graphics we need mathematics both for describing our scenes and also for performing operations on them, such as projection and various transformations. n Coordinate systems (right- and left- handed), serve as a reference point. n 3 axes labelled x, y, z at right angles.

4
4 Co-ordinate Systems X Y Z Right-Handed System (Z comes out of the screen) X Y Z Left-Handed System (Z goes in to the screen)

5
5 Points, P (x, y, z) n Gives us a position in relation to the origin of our coordinate system

6
6 Vectors, V (x, y, z) n Represent a direction (and magnitude) in 3D space n Points != Vectors Vector +Vector = Vector Point – Point = Vector Point + Vector = Point Point + Point = ?

7
7 Vectors, V (x, y, z) v w v + w Vector addition sum v + w v 2v (-1)v (1/2)V Scalar multiplication of vectors (they remain parallel) v w Vector difference v - w = v + (-w) v -w-w v - w x y Vector OP P O

8
8 Vectors V n Length (modulus) of a vector V (x, y, z) |V| = n A unit vector: a vector can be normalised such that it retains its direction, but is scaled to have unit length:

9
9 Dot Product u · v = x u ·x v + y u ·y v + z u ·z v u · v = |u| |v| cos cos = u · v/ |u| |v| n This is purely a scalar number not a vector. n What happens when the vectors are unit n What does it mean if dot product == 0 or == 1?

10
10 Cross Product n The result is not a scalar but a vector which is normal to the plane of the other 2 n Can be computed using the determinant of: u x v = i(y v z u -z v y u ), -j(x v z u - z v x u ), k(x v y u - y v x u ) n Size is u x v = |u||v|sin n Cross product of vector with it self is null

11
11 Parametric equation of a line (ray) Given two points P 0 = (x 0, y 0, z 0 ) and P 1 = (x 1, y 1, z 1 ) the line passing through them can be expressed as: P(t) = P 0 + t(P 1 - P 0 ) x(t) = x 0 + t(x 1 - x 0 ) y(t) = y 0 + t(y 1 - y 0 ) z(t) = z 0 + t(z 1 - z 0 ) = With - < t <

12
12 Equation of a sphere a b c hypotenuse a 2 + b 2 = c 2 P xpxp ypyp (0, 0) r x 2 + y 2 = r 2 n Pythagoras Theorem: n Given a circle through the origin with radius r, then for any point P on it we have:

13
13 Equation of a sphere If the circle is not centred on the origin: (0, 0) P xpxp ypyp r xcxc ycyc a b a b a 2 + b 2 = r 2 We still have but a = x p - x c b = y p - y c So for the general case (x- x c ) 2 + ( y- y c ) 2 = r 2 (x p,y p ) (x c,y c )

14
14 Equation of a sphere Pythagoras theorem generalises to 3D giving a 2 + b 2 + c 2 = d 2 Based on that we can easily prove that the general equation of a sphere is: (x- x c ) 2 + ( y- y c ) 2 + ( z- z c ) 2 = r 2 and at origin: x 2 + y 2 + z 2 = r 2

15
15 Matrix Math ©Anthony Steed 2001

16
16 Vectors and Matrices n Matrix is an array of numbers with dimensions M (rows) by N (columns) 3 by 6 matrix element 2,3 is (3) n Vector can be considered a 1 x M matrix

17
17 Types of Matrix n Identity matrices - I n Diagonal n Symmetric Diagonal matrices are (of course) symmetric Identity matrices are (of course) diagonal

18
18 Operation on Matrices n Addition Done elementwise n Transpose Flip (M by N becomes N by M)

19
19 Operations on Matrices n Multiplication Only possible to multiply of dimensions –x 1 by y 1 and x 2 by y 2 iff y 1 = x 2 resulting matrix is x 1 by y 2 –e.g. Matrix A is 2 by 3 and Matrix by 3 by 4 resulting matrix is 2 by 4 –Just because A x B is possible doesnt mean B x A is possible!

20
20 Matrix Multiplication Order n A is n by k, B is k by m n C = A x B defined by n BxA not necessarily equal to AxB

21
21 Example Multiplications

22
22 Inverse n If A x B = I and B x A = I then A = B -1 and B = A -1

23
23 3D Transforms n In 3-space vectors are transformed by 3 by 3 matrices

24
24 Scale n Scale uses a diagonal matrix n Scale by 2 along x and -2 along z

25
25 Rotation n Rotation about z axis n Note z values remain the same whilst x and y change Y X

26
26 Rotation X, Y and Scale n About X n About Y n Scale (should look familiar)

27
27 Homogenous Points n Add 1D, but constrain that to be equal to 1 (x,y,z,1) n Homogeneity means that any point in 3- space can be represented by an infinite variety of homogenous 4D points ( ) = ( ) = ( ) n Why? 4D allows as to include 3D translation in matrix form

28
28 Homogenous Vectors n Vectors != Points n Remember points can not be added n If A and B are points A-B is a vector n Vectors have form (x y z 0) n Addition makes sense

29
29 Translation in Homogenous Form n Note that the homogenous component is preserved (* * * 1), and aside from the translation the matrix is I

30
30 Putting it Together n R is rotation and scale components n T is translation component

31
31 Order Matters n Composition order of transforms matters Remember that basic vectors change so direction of translations changed

32
32 Exercises n Calculate the following matrix: /2 about X then /2 about Y then /2 about Z (remember then means multiply on the right). What is a simpler form of this matrix? n Compose the following matrix: translate 2 along X, rotate /2 about Y, translate -2 along X. Draw a figure with a few points (you will only need 2D) and then its translation under this transformation.

33
33 Matrix Summary n Rotation, Scale, Translation n Composition of transforms n The homogenous form

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google