168 471 computer graphics, kku. lecture 41 the computer programming laws any given program, when...

42
The Computer Programming Laws • Any given program, when running, is obsolete. • Any given program costs more and takes longer. • If a program is useful, it will have to be changed. • If a program is useless, it will have to be documented. • Any given program will expand to fill all available memory. • The value of a program is proportional to the weight of its output. • Program complexity grows until it exceeds the capability of the programmer who must maintain it.

Upload: eugene-mccoy

Post on 18-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

1

The Computer Programming Laws

• Any given program, when running, is obsolete.

• Any given program costs more and takes longer.

• If a program is useful, it will have to be changed.

• If a program is useless, it will have to be documented.

• Any given program will expand to fill all available memory.

• The value of a program is proportional to the weight of its output.

• Program complexity grows until it exceeds the capability of the programmer who must maintain it.

Page 2: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

2

Points

• 3One of the fundamental objects in D space th athas posi t i on.

• TTT TTTTT TTT TTT TTTTTTTTT TT TTTTTTTT TTTTTTcs.

• Distinguishedf r omeach ot her wi t h i t s posi t i on.• Drawn as dots.• TTTTTTT TT TTTTTTTTTTT TTTT TTTTTTT TTTT TT

P TTT Q.

• TTT TTTTTTTTT TTTTTTTTTT TTTTTT TT TTTTTTT TT TTTTTTTTT , points componentwise by utilizing parenthesis

e.g(x,y,z).

Page 3: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

3

Trigonometry

Page 4: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

4

Polar Coordinates

Page 5: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

5

Parametric Functions

Page 6: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

6

Parametric Lines

Page 7: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

7

Parametric Circles

Page 8: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

8

Plotting Parametric Functions

Page 9: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

9

• The fundamental 3D space objects like points.• Hasbot h magni t ude and di r ect i on.• Butposi t i onl ess.• Drawn as lines segments with arrow.• Denoted by lower case letters with an arrow ab

TTT TTTT TT • we represent vectors componentwise by utilizin

TTT T.< u,v,w>.• TTT TTTT TTTT TT TTTTT P TTT Q TTTTT TTTTTT ,

T TTTTTT TTTTTT TTTT TTTT

Vectors

v

v w

and

v P - Q

v

Page 10: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

10

Vectors

Page 11: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

11

Properties of Vectors

Page 12: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

12

Properties of Vectors (Cont.)

Page 13: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

13

“Multiplying” Vectors

Page 14: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

14

Vector Projection

Page 15: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

15

Planes

Page 16: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

16

Planes (Cont.)

Page 17: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

17

Matrices

Page 18: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

18

Matrix Multiplication

Page 19: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

19

Matrices (Cont.)

Page 20: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

20

Matrix Inversion

Page 21: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

21

• Cartesian coordinate system• Frame-based coordinate system• Device space• Screen Space• Image Space• Object Space• World Space

Coordinate Systems

Page 22: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

22

Cartesian coordinate system

Right-hand system

z

x y

Right-hand system

x

z

y

Page 23: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

23

Cartesian coordinate system(Cont.)

• In the computer graphics community• In computer graphics

Right-hand system

z

x

y

Right-hand system

x

z

y

Page 24: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

24

Frame-based coordinate system

• Consists of an origin and linearly independent vectors

( , , , )F u v w O

u

v

w

O

Page 25: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

25

• The actual coordinate system by which points are plotted on the graphics device.

• Measured in pixels• On SGI machines

– (0,0) is the lower left corner of a window.– X value increases to the right.– Y value increases upward.

• On Window platform– (0,0) is the upper left corner of a window.– X value increases to the right.– Y value increase downward.

Device Space

x

x

y

y

Page 26: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

26

Screen Space

• Defined to be the square on the xy plane.

• TTTTTT TT TTTTTT TTTTT TT TTTT TTTTTTT TTT T peci fi c gr aphi cs devi ces

1 , 1x y

Page 27: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

27

Image Space

• Used in 3-D system to allow for depth calculations.

• Defined by• Points in this space are mapped onto screen

space by projecting them onto the plane .• For example, any point in image space

will be protected to the center of the display screen.

1 , , 1x y z

0z (0,0, )z

Page 28: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

28

World Space

• The coordinate system of the scene • Must be projected into image space for

viewing.

Page 29: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

29

Object Space

• Localized system of an object being created.• After objects are created, about the world

space they can be– transformed– duplicated– moved– .etc

Page 30: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

30

Affine Space

• Made up of points and vectors• In affine space,

Page 31: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

31

Affine Space (Cont.)

• Vectors can be added, but points cannot.• Vectors can be scaled, but point cannot.

That is

Page 32: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

32

What is Affine Combination?

If are points and are scalars such that

then

is defined to be the point

Page 33: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

33

Affine Combination of 2 Points

TTT P1

TTT P2

TTTTTT TT TT TTTTTT TTTTTT TTTTTTTT, the expression

This P point represents a point on the line that passes

through P1 and P2

T TTT TTTT TT then P is somewhere on the line

segment joining P1 and P2 .

Page 34: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

34

Affine Combination of 3 Points

Consider three points P1 P2 and P3 that form a triangle,a point P can be defined by

or

then the point will be within (or on the boundary) of the triangle.

If

Page 35: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

35

Convex VS Non-Convex

Convex Set Non-Convex Set

Page 36: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

36

Coordinates of a point in the frame

Given a frame , a point P can be written

as Where O is an origin of the frame and

so the point can be written uniquely as

The set of values are the coordinates TT P relative to the frame .

Page 37: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

37

Cartesian Frames

The 2D standard Cartesian frame, denoted as , has A point P = will has the coordinate (x,y) relative to this frame

A Cartesian frame with any dimension consists of(0,0,…..,0) as an origin<1,0,…,0>, <0,1,…,0>,…, <0,0,…,1> as

basis vectors

Page 38: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

38

Examples

Given the frame which has the origin (0,0) and the vectors u = <1,0> and v = <1,1>, the point P that has its coordinate (5,3) in this frame, can be written as

which is the Cartesian coordinate (8,3).

or

Page 39: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

39

Matrix Representation of Points

T TTTT T TT TT TTTTTT TTTTT T T T , can write a point P uniquely as

or

Page 40: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

40

Matrix Representation of Vectors

Given a frame in an affine space , we can write a vector v uniquely as

or

Page 41: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

41

Converting between Frames

Suppose that we have the point P , with coordinates (3,2) in the frame

. What are the coordinates o

f the point in the frame ?

Consider the two frames and _ where

Page 42: 168 471 Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and

168 471 Computer Graphics, KKU. Lecture 4

42