Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mathematical fundamentals of 3D computer graphics 1.1 Manipulating three-dimensional structures 1.2 Vectors and computer graphics 1.3 Rays and computer.

Similar presentations


Presentation on theme: "Mathematical fundamentals of 3D computer graphics 1.1 Manipulating three-dimensional structures 1.2 Vectors and computer graphics 1.3 Rays and computer."— Presentation transcript:

1 Mathematical fundamentals of 3D computer graphics 1.1 Manipulating three-dimensional structures 1.2 Vectors and computer graphics 1.3 Rays and computer graphics 1.4 Bi-linear Interpolation of polygon properties 1.5 A basic maths engine using SIMD instructions

2 1.1 Manipulating three-dimensional structures This chapter deals with basic three-dimensional transformations and three-dimensional geometry. In computer graphics the most popular method for representing an object is the polygon mesh model. A polygon mesh model consists of a structure of vertices, each vertex being a three-dimensional point. 1.1.1 Three-dimensional geometry in computer graphics-affine transformations 1.1.2 Transformations for changing coordinate systems

3 1.1.1 Three-dimensional geometry in computer graphics-affine transformations Cartesian coordinate system  Right-handed  Left-handed

4 Transformation Translation Scaling Rotation

5 Homogeneous coordinates to for and scale factor  x = X/w  y = Y/w  z = Z/w Default w =1 then the matrix representation of a point is

6 Translation translation

7 Scaling

8 Rotation Z axis

9 Inverse of transformation T -1, negate T x, T y, T z S -1, replace S x, S y, S z by 1/S x,1/S y,1/S z R -1, negate the angle of rotation 

10 Inverse of transformation These transformation can be multiplied or concatenated together to give a net transformation matrix. For example : in the product M 2 M 1, the first matrix to be multiplied is M 1 translations are commutative, rotations are not and

11 Linear transformations examples Identity

12 Linear transformations examples Z-axis rotation

13 Linear transformations examples X-scale

14 Linear transformations examples Translation

15 Linear transformations examples Rotation followed by translation

16 Linear transformations examples Translation followed by rotation

17 Rotating about the object’s reference point (1) Translate the object to origin (2) Apply the desired rotation, and (3) Translate the object back to its original position The net transformation matrix is:

18 Rotating about the object’s reference point

19 1.1.2 Transformations for changing coordinate systems Coordinate systems  Object coordinate  World coordinate  View coordinate Transformations  Modeling transformation Object to world  Viewing transformation World to view

20 1.2 Vectors and computer graphics Addition of vectors Length of vectors Normal vectors and cross-products Normal vectors and dot products Vectors associated with normal vector

21 1.2.1 Addition of vectors X = V + W = (x 1,x 2,x 3 ) = (v 1 +w 1, v 2 +w 2, v 3 +w 3 )

22 1.2.2 Length of vectors Length of V Normalise vector V to produce a unit vector U

23 1.2.3 Normal vectors and cross- products Cross product i, j and k are the standard unit vectors

24 1.2.3 Normal vectors and cross- products The normal to the polygon is found by taking the cross product of these:

25 1.2.3 Normal vectors and cross- products If the surface is a bi-cubic parametric surface, then the orientation of the normal vector varies continuously over the surface. For a surface defined as Q (u, v) we find: We then define:

26 1.2.4 Normal vectors and products Dot product of vectors Using the cosine rule ( θis the angle between the vectors )

27 1.2.4 Normal vectors and products We can use the dot product to project a vector onto another vector. If we project any vector W onto V(V is a unit vector), then we have:

28 1.2.5 Vectors associated with the normal vector The light vector L is a vector whose direction is given by the line from the tail of the surface normal to the light source

29 1.2.5 Vectors associated with the normal vector The reflection vector R is given by the direction of the light reflected from the surface due to light incoming along direction L.

30 1.2.5 Vectors associated with the normal vector View vector V that this vector has any arbitrary orientation and we are normally interested in that component of light incoming in direction L that is reflected along V.

31 1.2.5 Vectors associated with the normal vector Consider the construction shown in figure.

32 1.3 Rays and computer graphics Ray geometry – intersections Intersections – ray – sphere Intersections – ray – convex polygon Intersections – ray – box

33 1.3.1 Ray geometry – intersections The most common calculation associated with rays is intersection testing. The most common technique used to make this more efficient is to enclose objects in the scene in bounding volume – the most convenient being a sphere.

34 1.3.2 Intersections – ray – sphere The intersection between a ray and a sphere is easily calculated. The end points of the ray are (x 1,y 1,z1), (x 2,y 2,z 2 ) then parametrise the ray: A sphere at center (l, m,n) of radius r is given by: Substituting for x, y, z gives a quadratic equation in t of the form:

35 1.3.2 Intersections – ray – sphere Solution: Determinant:  D>0 : 二根為前後二交點  D=0 : 相切於一點  D<0 : 沒有交點 If the intersection point is (x i, y i, z i ) and the centre of the sphere is (l, m, n) then the normal at the intersection point is :

36 1.3.3 Intersections – ray – convex polygon If an object is represented by a set of polygons and is convex then the straightforward approach is to test the ray individually against each polygon. We do this as follow:  Obtain an equation for the plane containing the polygon  Check for an intersection between this plane and the ray  Check that this intersection is contained by the polygon

37 1.3.3 Intersections – ray – convex polygon Example: 包含 polygon 的平面 :Ax + By + Cz + D = 0 Ray 的參數式: The intersection ( 將參數式代入平面求解 )

38 1.3.3 Intersections – ray – convex polygon If t<0. This means that the ray is in the half-space defined by the plane that does not contain the polygon. If the denominator is equal to zero which means that the line and plane are parallel. In this case the ray origin is either inside or outside the polyhedron.

39 1.3.3 Intersections – ray – convex polygon Test a point for containment by a polygon Simple but expensive method: 由此點畫直線連接多邊形各頂點, 若夾角的合為 360, 則交點 在此 polygon 內部, 否則此交點在 polygon 外部 Haines method: 依光線行進方向將每一平面分成 front-facing, back-facing: 分母>0: back-facing 分母<0: front-facing

40 1.3.3 Intersections – ray – convex polygon Haines algorithm {initialize t near to large negative value t far to large positive value} if {plane is back-facing} and (t<t far ) then t far = t if {plane is front-facing} and (t>t near ) then t near = t if (t near >t far ) then {exit – ray misses}

41 1.3.3 Intersections – ray – convex polygon

42 1.3.1 Intersections – ray – box Treat each pair of parallel planes in turn. Calculating the distance along the ray to the first plane (t near ) and the distance to the second plane (t far ). The larger value of t near and the smaller value of t far is retained between comparisons. If the larger value of t near is greater than smaller value of t far, the ray cannot intersect the box.

43 1.3.1 Intersections – ray – box

44 1.4 Bi-linear interpolation of polygon properties Bi-linear interpolation equations Final equation (constant value calculated once per scan line)

45 1.4 Bi-linear interpolation of polygon properties


Download ppt "Mathematical fundamentals of 3D computer graphics 1.1 Manipulating three-dimensional structures 1.2 Vectors and computer graphics 1.3 Rays and computer."

Similar presentations


Ads by Google