3D Computer Graphics. Jared Kirschner. November 8, 2010

Similar documents
Computer Graphics: Geometric Transformations

UNIT 2 2D TRANSFORMATIONS

Graphics and Interaction Transformation geometry and homogeneous coordinates

COMP30019 Graphics and Interaction Transformation geometry and homogeneous coordinates

Transformations Week 9, Lecture 18

Computer Graphics 7: Viewing in 3-D

3D Mathematics. Co-ordinate systems, 3D primitives and affine transformations

Representing 2D Transformations as Matrices

Shadows in Computer Graphics

Overview. Affine Transformations (2D and 3D) Coordinate System Transformations Vectors Rays and Intersections

THE VIEWING TRANSFORMATION

Math 259 Winter Unit Test 1 Review Problems Set B

MATRIX REVIEW PROBLEMS: Our matrix test will be on Friday May 23rd. Here are some problems to help you review.

Matrices. Chapter Matrix A Mathematical Definition Matrix Dimensions and Notation

Affine Transformation. Edith Law & Mike Terry

2D and 3D Transformations AUI Course Denbigh Starkey

The Importance of Matrices in the DirectX API. by adding support in the programming language for frequently used calculations.

521493S Computer Graphics Exercise 2 Solution (Chapters 4-5)

Computer Graphics. Chapter 5 Geometric Transformations. Somsak Walairacht, Computer Engineering, KMITL

Vector Algebra Transformations. Lecture 4

(Refer Slide Time: 00:04:20)

3D Geometry and Camera Calibration

2D Image Transforms Computer Vision (Kris Kitani) Carnegie Mellon University

Midterm Exam Fundamentals of Computer Graphics (COMP 557) Thurs. Feb. 19, 2015 Professor Michael Langer

Math 7 Elementary Linear Algebra PLOTS and ROTATIONS

Cs602-computer graphics MCQS MIDTERM EXAMINATION SOLVED BY ~ LIBRIANSMINE ~

3D Transformations World Window to Viewport Transformation Week 2, Lecture 4

EECE 478. Learning Objectives. Learning Objectives. Linear Algebra and 3D Geometry. Linear algebra in 3D. Coordinate systems

Computer Graphics Hands-on

COMP30019 Graphics and Interaction Three-dimensional transformation geometry and perspective

Object Representation Affine Transforms. Polygonal Representation. Polygonal Representation. Polygonal Representation of Objects

Polynomials. Math 4800/6080 Project Course

THE CAMERA TRANSFORM

2D Object Definition (1/3)

1.5 Equations of Lines and Planes in 3-D

Transformations. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

2D TRANSFORMATIONS AND MATRICES

2D transformations: An introduction to the maths behind computer graphics

Level 3 will generally

Matrix Operations with Applications in Computer Graphics

Figure 1. Lecture 1: Three Dimensional graphics: Projections and Transformations

Visual Recognition: Image Formation

CS 445 / 645 Introduction to Computer Graphics. Lecture 21 Representing Rotations

1.5 Equations of Lines and Planes in 3-D

L1 - Introduction. Contents. Introduction of CAD/CAM system Components of CAD/CAM systems Basic concepts of graphics programming

CHAPTER 3. Single-view Geometry. 1. Consequences of Projection

To graph the point (r, θ), simply go out r units along the initial ray, then rotate through the angle θ. The point (1, 5π 6

Anamorphic Art with a Tilted Cylinder

1 Affine and Projective Coordinate Notation

COMP 558 lecture 19 Nov. 17, 2010

Models and The Viewing Pipeline. Jian Huang CS456

Introduction Ray tracing basics Advanced topics (shading) Advanced topics (geometry) Graphics 2010/2011, 4th quarter. Lecture 11: Ray tracing

Coordinate transformations. 5554: Packet 8 1

Hello, welcome to the video lecture series on Digital Image Processing. So in today's lecture

Last week. Machiraju/Zhang/Möller/Fuhrmann

Advanced Computer Graphics Transformations. Matthias Teschner

Math background. 2D Geometric Transformations. Implicit representations. Explicit representations. Read: CS 4620 Lecture 6

ME-430 Introduction to CAD Lecture Notes- Part 3

The diagram above shows a sketch of the curve C with parametric equations

DD2429 Computational Photography :00-19:00

Answers to practice questions for Midterm 1

Image warping , , Computational Photography Fall 2017, Lecture 10

Game Mathematics. (12 Week Lesson Plan)

Computer Graphics: Viewing in 3-D. Course Website:

Rigid Body Motion and Image Formation. Jana Kosecka, CS 482

Computing the 3D Viewing Transformation

CSE328 Fundamentals of Computer Graphics

Revision Problems for Examination 2 in Algebra 1

Institutionen för systemteknik

Game Engineering CS S-05 Linear Transforms

Homogeneous Coordinates and Transformations of the Plane

The Three Dimensional Coordinate System

To graph the point (r, θ), simply go out r units along the initial ray, then rotate through the angle θ. The point (1, 5π 6. ) is graphed below:

Introduction to Homogeneous coordinates

Computer Vision. Coordinates. Prof. Flávio Cardeal DECOM / CEFET- MG.

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Transformations. CSCI 420 Computer Graphics Lecture 4

Monday, 12 November 12. Matrices

INTRODUCTION TO COMPUTER GRAPHICS. It looks like a matrix Sort of. Viewing III. Projection in Practice. Bin Sheng 10/11/ / 52

Lecture 5 2D Transformation

Part 3: 2D Transformation

Assignment #6: Subspaces of R n, Bases, Dimension and Rank. Due date: Wednesday, October 26, 2016 (9:10am) Name: Section Number

Camera Model and Calibration

CHAPTER 1 Graphics Systems and Models 3

CMSC427 Final Practice v2 Fall 2017

Chapter 2 - Basic Mathematics for 3D Computer Graphics

GEOMETRIC TRANSFORMATIONS AND VIEWING

Overview. By end of the week:

AQA GCSE Further Maths Topic Areas

EXAMINATIONS 2017 TRIMESTER 2

Basics of Computational Geometry

Computer Vision cmput 428/615

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI

Perspective Mappings. Contents

Parallel and perspective projections such as used in representing 3d images.

Animated Cartoons by Computer Using Ellipsoids

3 Identify shapes as two-dimensional (lying in a plane, flat ) or three-dimensional ( solid ).

Kinematics of Wheeled Robots

CS 4204 Computer Graphics

18.02 Final Exam. y = 0

Transcription:

3D Computer Graphics Jared Kirschner November 8, 2010 1

Abstract We are surrounded by graphical displays video games, cell phones, television sets, computer-aided design software, interactive touch screens, instrument panels, and countless others. In order to understand how image data can be manipulated and rendered on a screen to produce a coherent, realistic image, we need only to understand some basic concepts of linear algebra. To produce an image, we will need a set of vectors (points) defined in the relevant dimension (R n where n 2), mathematical information defining the connections between points (in the form of lines or curves), and information concerning how to fill the region bounded by the sets of connected points. [1] For the purposes of this paper, we will be focusing on the vectors in R 3 which define the nodes of an image. By performing linear transformations on the set of vectors through matrix multiplication, we can translate, rotate, scale, and distort an image in R n, among other possibilities. But ultimately, to display the graphics in two dimensions, we must perform a linear transformation from R n to R 2. Through the use of perspective projections, we can create a two-dimensional set of data which appears to the observer as an object in n-dimensional space (usually R 3 ). By combining these transformations, the complex animations and visuals we have grown so accustomed to in our modern world are made possible. 1 Vector Data To represent a three-dimensional object, it is trivial to state that we need at least three dimensions of data per vector. However, in the case of computer graphics, we actually use (n + 1)-dimensions of data to store and manipulate n-dimensions of data. A vector p = (x, y, z) in R 3 can be represented as a plane in R 4 at 1 unit above the xyz-plane by the homogenous coordinates of h = (X, Y, Z, H) where H 0 and: x = X H, y = Y H, z = Z H (1) Using a homogenous coordinate system provides two key advantages. First, it allows scaling and translation to be achieved by matrix multiplication. Second, it allows for perspective projections which make a twodimensional image appear three-dimensional.

2 Data Transformations Before processing the vector data to produce a realistic image, it is necessary to perform transformations on the object such that it has the desired properties in R 3. Translation, rotation, shearing, and scaling are examples of transformations one might want to do before processing the data into an image. As shearing and scaling are fairly elementary operations, they will not be discussed here. 2.1 Translation In a non-homogenous coordinate system, translation must be accomplished by matrix addition rather than matrix multiplication. This is because T (x, y, z) (x + t 1, y + t 2, z + t 3 ) where t = (t 1, t 2, t 3 ) is the translation vector in R 3 is not a linear transformation. All matrix transformations are linear transformations, therefore, the transformation T cannot be obtained from matrix multiplication. As the mathematics of computer graphics is intimately connected with matrix multiplication, we will instead perform translation by matrix multiplication using homogenous coordinates: [2] X + t 1 ] X t Y [ Y + t 2 Z + t 3 = I3 0 1 H Z H (2)... where I 3 is the 3 3 identity matrix, and t is the translation vector in R 3. The partitioned matrix given in Equation 2 can be extended to any dimensional space R n. However, in this particular case, we are examining how a vector in R 3 represented by homogenous coordinates can be successfully translated using matrix multiplication. 2.2 Rotation Let us examine a vector v in R 2. In order to define a linear transformation T such that T ( v) is a rotation of v by θ radians, we must find the standard matrix A of the transformation such that T ( v) = A v. The columns of the standard matrix A will be the transformations of the columns of the identity matrix, as shown below. [ ] [ ] [ ] v1 1 0 v = = v 1 + v 0 2 = v 1 1 e 1 + v 2 e 2 Therefore, v 2 2

T ( v) = T (v 1 e 1 + v 2 e 2 ) = v 1 T (e 1 ) + v 2 T (e 2 ) = [T (e 1 ) T (e 2 )] v = A v If we rotate the columns of the identity matrix by an angle θ, it can be seen that T (e 1 ) = (cos(θ), sin(θ)) and T (e 2 ) = ( sin(θ), cos(θ)) (refer to Figure 1). Therefore: [ ] cos(θ) sin(θ) A = sin(θ) cos(θ). Figure 1: Rotation of the columns of the identity of the xy-plane about the z-axis. A similar analysis can be used to determine the standard matrix A for a rotation in R 3 along any axis. [ ] T ( A 0 h) = h 0 1 Unfortunately, such a transformation only rotates the vector about the origin. In computer graphics, the ability to rotate about a specific point is generally more useful. To accomplish this, we can combine translational and rotational transformations. For a given homogenous coordinate h and a point of rotation p, we will translate h by p, thus moving the point of rotation p to the origin. After performing the rotation about the origin, we can move the point of rotation from the origin back to its original position 3

by translating by p. Therefore, the composite transformation S( h) is equal to T ( h p) + p (see Equation 3). ([ ] [ ] [ ]) S( I3 p A 0 I3 p h) = h (3) 0 1 0 1 0 1 3 Image Transformations After an object has the desired properties in R 3, it must be transformed into R 2 for display. The easiest way to do this would be to perform a simple projection of each vector onto a two-dimensional plane such as the xy-axis. Unfortunately, this would not produce a very realistic image. To create a realistic image, we must take into consideration factors such as the position of the observer (perspective) and of light sources (shadows), among others. 3.1 Perspective Projection Let us define a point of observation p c = (b, c, d) in R 3 from which the threedimensional object is being viewed. This point is referred to as the center of projection. If we project each point of the image p in R 3 onto the xy-plane from the center of projection, we can create a two-dimensional representation of the three-dimensional image. To project a point onto a plane, we must find the location at which the line through p and p c intersects the desired plane (see Figure 2). Figure 2: Perspective projection of a point (x, y, z) in R 3 onto the xy-plane from the center of projection (b, c, d). 4

The line l(t) through any two vectors v 1 and v 2 can be defined as l(t) = v 1 + t( v 2 v 1 ). As such, we can define a line through the center of projection p c and a point p in R 3 as: b + t(x b) l(t) = pc + t( p p c ) = c + t(y c) (4) d + t(z d) We can find the point p = (x, y, z ) where l(t) intersects with the xy-plane by defining z = 0. This allows us to solve for t: p : 0 = l(t) 3 = d + t(z d) t = d d z Now that we have solved for t, from Equation 4 we can define the point b + p = c + d + d d z d d z d d z (x b) (y c) = (z d) x b d z 1 1 d z y c d z 1 1 d z 0 (5) For the homogenous coordinate h = (X, Y, Z, H), we can express its projection onto the xy-plane as ( ) h x b d = z, y c 1 1 d z, 0, H. In a homogenous d z 1 1 d z coordinate system, scalar multiplication does not affect the vector (x, y, z) in R 3 (refer to Equation 1). As such, we can multiply h by the scalar ( 1 1z) d to eliminate the fractions. We can express the perspective transformation U p as U p (X, Y, Z, H) ( x b z, y c z, 0, H(1 1z)). Let G d d d p be the standard matrix of transformation U p ; the matrix equation G p h = h can be expressed as follows: 1 0 b 0 X X b d 0 1 c 0 d Y 0 0 0 0 Z = z d Y c z d 0 (6) 0 0 1 1 H H(1 1z) d d To display the image in R 2, we simply divide the vector by H (the fourth element of the vector) as per Equation 1 to force the fourth entry to 1. When H = 1, (X, Y, Z) = (x, y, z), allowing for direct mapping. As the z-component of this vector is zero because we have projected it onto the xyplane, it can readily be displayed as R 2 by dropping the last two elements (Z and H). To accomplish this with matrix multiplication, we can left-multiply the vector by the following matrix to produce a projection onto R 2 : 5

[ 1 0 0 ] 0 0 1 0 0 3.2 Realistic Shadows To create realistic shadows, we need to define at least one source of lighting p s = (b, c, d) and a surface of projection. In most cases, this surface of projection is the ground. For our purposes, we will assume a flat surface at y = 0, but the methods discussed below can be used to determine the projection of a shadow onto any surface. As in Section 3.1, we begin by defining the line l(t) which passes through a point p and the surface of projection. In this case, l(t) = p s + t( p p s ). To determine the point p = (x, y, z ) at which l(t) passes through the xz-plane (y = 0), we can solve for the parameter t: 0 = l(t) 3 = c + t(y c) t = c c y By the methods discussed in Section 3.1, we can express the perspective transformation U s as U s (X, Y, Z, H) ( x by, 0, z dy, H(1 1y)). Let c c c G s be the standard matrix of transformation U s ; the matrix equation G s h = h can be expressed as follows: 1 b 0 0 X c 0 0 0 0 Y 0 d 1 0 Z = c 1 0 1 1 H c X b c y 0 Z d c y H(1 1 c y) (7) To display an image with a shadow, we will perform a perspective projection (refer to Section 3.1) on both the image data h and its shadow projection onto the xy-plane h. After the perspective projection, we will once again divide by H as per Equation 1 and remove the z-component of the resulting vector for display in R 2 by a simple projection. 4 The Results Now that we have covered some of the basics of computer graphics, we will discuss how to produce an animation. We start by defining our image as a collection of vectors h in a homogenous coordinate system. These vectors will be arranged columnwise in a matrix M h to produce our data matrix such that M h = [ v 1... v m ] where m is the number of vectors in the image. To construct 6

an image, we also need to define the connections between vectors. This can be done with an m m adjacency matrix K where the position K ij denotes whether or not a connection exists from v i to v j. Though this matrix can become very large depending on the number of vectors in an image, it can be compressed by conversion to a sparse matrix. However, sparse matrices are beyond the scope of this discussion. Figure 3 shows an animation of a wire-frame car where the point of observation pans from p c1 to p c2 with a light source at p s. The wire-frame car is represented as a matrix M h with columns of the homogenous coordinates of each vector in the image. A series of transformations is performed on M h before it is displayed as a two-dimensional image. We first perform data transformations which simply map R 4 onto R 4. To display the image, we perform image transformations from R 4 to R 2. Figure 3: A series of frames showing the view of a wire-frame car as the point of observation pans from ( 50, 50, 50) to (50, 0, 50) with a light source at (0, 1000, 500). The wire-frame car itself is about 13 units wide, 4 units tall at its highest point, and 5 units wide. 7

To produce an animation of the type described above, we have several options. To make an object appear that it is moving, all that matters is the relative motion between the observer and the observed. As such, we can produce the same animation by translating the object with a data transformation or by moving the point of observation the same amount (thus changing the perspective projection an image transformation). A similar argument can be used to show that a perceived rotation can be obtained with a rotation (data transformation) or a change of perspective (image transformation). In this particular implementation, I have chosen the latter option. This is because the light source is defined in the reference frame of the observer. Therefore, for the car to have a constant shadow (stationary object with a moving observer), we must use image transformations. If we wish to have a dynamic shadow (moving object with a stationary observer), we must use data transformations. Though there will be no observable difference between the method used for a light source at a significant distance on a relative scale (such as the sun), a significant difference between methods will be observed for local light sources (such as candles, light bulbs, et cetera). To produce the image of the car in two-dimensions, the following equation was used: 1 0 p 1(t) 0 (t) 0 1 p 1(t) M car = 0 (t) 0 0 0 0 M h 0 0 1 1 (t)... where p(t) is the parametric equation of the center of observation dependent on time t such that p(t) = p 1 + p 2 p 1 t max for t t max and M car is the resulting matrix. To produce the shadow of the car in two-dimensions, we perform a projection onto the xz-plane (y = 0), representing the ground, and then perform a perspective projection on the result: 1 0 p 1(t) 0 1 ps 1 (t) p s2 0 0 0 1 p 1(t) M shadow = 0 0 0 0 0 (t) 0 0 0 0 0 ps 3 p s2 1 0 M h 0 0 1 1 1 0 (t) p s2 1 1 We then normalize each column of matrices M car and M shadow by their fourth entries (refer to Equation 1). To map the R 4 onto R 2, we can simply delete the third and fourth row of the matrices or we can left-multiply by the standard matrix [ I 2 0 0 ] of a projection transformation. These vectors 8

are then connected by the information contained in the adjacency matrix K. In this case, straight lines are used to connect vectors (refer to Figure 3). However, other methods can be used to connect vectors, and would simply require additional mathematical data. 9

References [1] Lay, D. C. (2003). Linear Algebra. Retrieved October 19, 2010, from Pearson Education: http://media.pearsoncmg.com/aw/aw lay linearalg updated cw 3/cs apps/lay03 02 cs.pdf [2] Lay, D. C. (2006). Linear Algebra and Its Applications. Pearson/Addison- Wesley. 10