470 likes | 697 Views
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.
E N D
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
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
1.1.1 Three-dimensional geometry in computer graphics-affine transformations • Cartesian coordinate system • Right-handed • Left-handed
Transformation • Translation • Scaling • Rotation
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
Translation • translation
Scaling • Scaling
Rotation • Rotation • Z axis
Inverse of transformation • T-1, negate Tx, Ty, Tz • S-1, replace Sx, Sy, Szby 1/Sx,1/Sy,1/Sz • R-1, negate the angle of rotation
Inverse of transformation • These transformation can be multiplied or concatenated together to give a net transformation matrix. For example: • in the product M2M1, the first matrix to be multiplied is M1 • translations are commutative, rotations are not and
Linear transformations examples • Identity
Linear transformations examples • Z-axis rotation
Linear transformations examples • X-scale
Linear transformations examples • Translation
Linear transformations examples • Rotation followed by translation
Linear transformations examples • Translation followed by rotation
Rotating about the object’s reference point • Translate the object to origin • Apply the desired rotation, and • Translate the object back to its original position The net transformation matrix is:
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
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
1.2.1 Addition of vectors • X = V + W = (x1,x2,x3) = (v1+w1, v2+w2, v3+w3)
1.2.2 Length of vectors • Length of V • Normalise vector V to produce a unit vector U
1.2.3 Normal vectors and cross-products • Cross product • i, j and k are the standard unit vectors
1.2.3 Normal vectors and cross-products • The normal to the polygon is found by taking the cross product of these:
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:
1.2.4 Normal vectors and products • Dot product of vectors • Using the cosine rule ( θis the angle between the vectors )
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:
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
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.
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.
1.2.5 Vectors associated with the normal vector • Consider the construction shown in figure.
1.3 Rays and computer graphics • Ray geometry – intersections • Intersections – ray – sphere • Intersections – ray – convex polygon • Intersections – ray – box
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.
1.3.2 Intersections – ray – sphere • The intersection between a ray and a sphere is easily calculated. The end points of the ray are (x1,y1,z1), (x2,y2,z2) 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:
1.3.2 Intersections – ray – sphere • Solution: • Determinant: • D>0 :二根為前後二交點 • D=0 :相切於一點 • D<0 :沒有交點 • If the intersection point is (xi, yi, zi ) and the centre of the sphere is (l, m, n) then the normal at the intersection point is :
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
1.3.3 Intersections – ray – convex polygon • Example: • 包含polygon的平面:Ax + By + Cz + D = 0 • Ray 的參數式: • The intersection (將參數式代入平面求解)
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.
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
1.3.3 Intersections – ray – convex polygon • Haines algorithm {initialize tnear to large negative value tfar to large positive value} if {plane is back-facing} and (t<tfar) then tfar = t if {plane is front-facing} and (t>tnear) then tnear = t if (tnear>tfar) then {exit – ray misses}
1.3.1 Intersections – ray – box • Treat each pair of parallel planes in turn. • Calculating the distance along the ray to the first plane (tnear) and the distance to the second plane (tfar). • The larger value of tnear and the smaller value of tfar is retained between comparisons. • If the larger value of tnearis greater than smaller value of tfar, the ray cannot intersect the box.
1.4 Bi-linear interpolation of polygon properties • Bi-linear interpolation equations • Final equation (constant value calculated once per scan line)