1. Trang chủ
  2. » Giáo Dục - Đào Tạo

Lecture computer graphics and virtual reality slides lesson 3 basic entity algorithms

38 0 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Basic Entity Algorithms
Tác giả Trinh Thanh Trung
Trường học Hust
Chuyên ngành ICT
Thể loại Lecture Slides
Định dạng
Số trang 38
Dung lượng 1,05 MB

Nội dung

Trang 7 Problems■ It seems to work okay for lines with a slope of 1 or less■ Doesn’t work well for lines with slope greater than 1■ Lines become more discontinuous in appearance■ We must

Trang 1

Lesson 3

Basic entity algorithms

Trinh Thanh Trung School of ICT, HUST

Trang 3

Rasterization: Background

■ Converting a continuous object in the world into

a discrete object in the computer

■ We need to lit the pixels instead of drawing a continuous line

Trang 4

Line representation

Trang 7

discontinuous in

appearance

than 1 pixel per column to make it work

Trang 8

DDA algorithm

■ DDA = Digital Differential Analyser

■ Treat line as parametric equation in t

Trang 9

DDA algorithm: Pseudo code

ddaline(x1, y1, x2, y2)

Trang 10

DDA algorithm: General algorithms

■ Choose appropriate value

for the number of steps (n)

Trang 11

DDA algorithm: General algorithms

ddaline(int x1, int y1, int x2, int y2)

Trang 12

DDA Algorithm: Cons

■ Need a lot of floating point arithmetic

□ 2 ‘round’s and 2 adds per pixel

■ Can we use only integer arithmetic?

□ Easier to implement in hardware

Trang 13

Bresenham algorithm

■ Developed in 1962 at IBM

■ Uses only integer addition, subtraction and bit

shifting, all of which are very cheap operations in

standard computer architectures

0 1

2

d2 d1

■ Chooses the integer y

corresponding to the pixel

center that is closest to the

ideal (fractional) y for the

same x; on successive

columns y can remain the

same or increase by 1

Trang 14

Bresenham algorithm: pseudo code

Trang 15

Mid-point algorithm

At step p, assume pixel (x p , y p ) was lit

Check where the line intersects with x= x p +1

Lit (x p+1 , y p ) or (x p+1 , y p+1 ) , whichever is

■ closer to the intersection

Trang 16

i i i

i

i i i

i

y x c

by ax

y x c

by ax

y x c

by ax

,0

,0

,0

++

++

=+

above line below line

Trang 17

Mid-point algorithm

■ Assume slope is less than 1 and current pixel is (xi, yi)

■ Next mid-point will be (xi + 1, yi + ½)

■ We calculate di (called decision variable)

+

=

2 1 1

Trang 18

Choices for Current pixel

Choices for Next pixel

M A

B

Trang 19

Mid-point algorithm

■ If A is chosen: We update the decision variable

b a d

c y

b x

a d

y x

i

i i

i i

i

++

2

3,

Previous Pixel

(xi,yi)

Choices for Current pixel

Choices for Next pixel

M A

B

Trang 20

Mid-point algorithm

■ If B is chosen: We update the decision variable

Previous Pixel

(xi,yi)

Choices for Current pixel

Choices for Next pixel

M A

B

a d

c y

b x

a d

y x

i

i i

i i

2

1,

Trang 21

Mid-point algorithm: Pseudo code

d = d+2*(dy-dx)

x = x+1

y = y+1 endif

Trang 22

Mid-point algorithm: Summary

■ Choose between 2 pixels at each step based upon the sign of a decision variable

■ Update the decision variable based upon which pixel is chosen

■ Start point is simply first endpoint (xi,yi)

■ Need to calculate the initial value for d

Trang 23

What if slope is not

Trang 24

Circle & elipse representation

Trang 25

Circle representation

■ Use mid-point algorithm for 1/8 circle, then use symmetry

Trang 26

Circle representation

■ Implicit form of a circle

With d i is the decision variable at a specific point

circle

on is,

if 0

circleinside

is,

if 0

i i

i i i

y x

y x

y x d

Trang 27

Circle representation

■ As with the line, we determine the value of the decision variable by substituting the mid-point of the next pixel into the implicit form of the circle:

If d i < 0 we choose pixel A otherwise we choose pixel B

□ Note: we currently assume the circle is centered at the origin

2 2

+

=

Trang 28

Circle representation

■ Again, as with the line algorithm, the choice of A

or B can be used to determine the new value of d i+1

■ If A chosen then next midpoint has the following decision variable:

■ Otherwise if B is chosen then the next decision variable is given by:

3 2

2

1 2

2

1 ,

2 2

1

+ +

i i

i i

i

x d

r y

x d

y x

5 2

2

2

3 2

2

3 ,

2 2

1

+

− +

i

i i

i i

i

y x

d

r y

x d

y x

Trang 29

Circle representation

If we assume that the radius is an integral value, then the first pixel drawn is (0, r) and the initial

value for the decision variable is given by:

Although the initial value is fractional, we note that all other values are integers.

r

r r

r d

4

11

2

1,

r

d0 =1 −

Trang 30

Circle representation: pseudo code

d = d+2*(x-y)+5

x = x+1

y = y-1 end if

SetPixel(cx+x,cy+y)

End while

initialisation

choose B choose A

Translate to the circle center stop at diagonal  end of octant

Trang 31

Ellipse representation

■ Use mid-point algorithm

■ Implicit form of an ellipse

□ 2a is the length of the major axis along the x axis.

□ 2b is the length of the minor axis along the y axis.

F x y = b x + a ya b =

■ For simplicity, we draw only

the arc of the ellipse that lies in

the first quadrant, the other

three quadrants can be drawn

by symmetry

Trang 32

Ellipse representation

■ Firstly we divide the quadrant into two regions

■ Boundary between the two regions is

□ the point at which the curve has a slope of -1

□ the point at which the gradient vector has the i and j components of equal magnitude

Trang 33

Character representation

Trang 35

Bitmap character: structure

Trang 36

Vector font

Also called True Type Font (ttf)

■ Flexible, suitable for any screen

Trang 37

Any questions?

Trang 38

Lecture notes provided by School of Information and

Communication Technology, Hanoi University of Science and

Technology.

Composed by Huynh Quyet Thang, Le Tan Hung, Trinh Thanh Trung and others

Edited by Trinh Thanh Trung

Special thanks to all the people who made and released these awesome resources for free:

■ Presentation template by SlidesCarnival

■ Photographs by Death to the Stock Photo ( license )

■ Diverse device hand photos by Facebook Design Resources

Ngày đăng: 02/03/2024, 13:59

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN