Transcript
Page 1: November 18, 20151. We could solve for y in terms of x ( x 0, y 0 ) are the origin points A Simple Circle Drawing Algorithm The equation for a circle

April 21, 2023 1

Page 2: November 18, 20151. We could solve for y in terms of x ( x 0, y 0 ) are the origin points A Simple Circle Drawing Algorithm The equation for a circle

We could solve for y in terms of x

( x0, y0 ) are the origin points

A Simple Circle Drawing Algorithm

The equation for a circle is:

where r is the radius of the circle

222 ryx

22 xry OR

April 21, 2023 2

Page 3: November 18, 20151. We could solve for y in terms of x ( x 0, y 0 ) are the origin points A Simple Circle Drawing Algorithm The equation for a circle

20020 220 y

20120 221 y

20220 222 y

61920 2219 y

02020 2220 y

Let r = 2022 xry

April 21, 2023 3

x0 = 0

Page 4: November 18, 20151. We could solve for y in terms of x ( x 0, y 0 ) are the origin points A Simple Circle Drawing Algorithm The equation for a circle

However, unsurprisingly this is not a brilliant solution!

Firstly, the resulting circle has large gaps where the slope approaches the vertical

Secondly, the calculations are not very efficientThe square (multiply) operationsThe square root operation – try really hard to avoid these!

We need a more efficient, more accurate solution

April 21, 2023 4

Page 5: November 18, 20151. We could solve for y in terms of x ( x 0, y 0 ) are the origin points A Simple Circle Drawing Algorithm The equation for a circle

Parametric polar representation

x = r . cos (ө)

y = r . sin (ө)

x = xc + r . cos (ө)

y = yc + r . sin (ө)

OR

Arc Length

x1 = r . cos (ө) x2 = r . cos (ө + dө)

y1 = r . sin (ө) y2 = r . sin (ө + dө)

dө: is a fixed angular step size April 21, 2023 5

Page 6: November 18, 20151. We could solve for y in terms of x ( x 0, y 0 ) are the origin points A Simple Circle Drawing Algorithm The equation for a circle

x2 = x1 . cos (dө) – y1 . sin (dө)

y2 = y1 . cos (dө) + x1 . sin (dө)

By using trigonometry ... get

dtheta = 1/r ;cdetheta = cos (dtheta) ;sdetheta = sin (detheta) ;x = 0 ;y = r ;while (x<=y){Plotpixel (x, y) ; // for eight points xtemp = x ;x = x * cdetheta – y * sdetheta ;y = y * cdetheta + xtemp * sdetheta ;}

April 21, 2023 6

Help for programming

Page 7: November 18, 20151. We could solve for y in terms of x ( x 0, y 0 ) are the origin points A Simple Circle Drawing Algorithm The equation for a circle

Bresenham’s algorithm for circles

Key idea: compute the initial octant only

Generate firstoctant

1

Reflect first octant about y=x2

Reflect firstquadrantabout x=0

3

Reflect uppersemicircleabout y=0

4

Page 8: November 18, 20151. We could solve for y in terms of x ( x 0, y 0 ) are the origin points A Simple Circle Drawing Algorithm The equation for a circle

Bresenham’s incremental circle algorithm

Example: circle of radius 8 Bright pixels:

initial pixel (0,8)(1,8)(2,8)(3,7)(4,7)(5,6)(6,5)(7,4)(7,3)(8,2)(8,1)end pixel (8,0)

April 21, 2023 8

Page 9: November 18, 20151. We could solve for y in terms of x ( x 0, y 0 ) are the origin points A Simple Circle Drawing Algorithm The equation for a circle

April 21, 2023 9

Page 10: November 18, 20151. We could solve for y in terms of x ( x 0, y 0 ) are the origin points A Simple Circle Drawing Algorithm The equation for a circle

Eight-Way Symmetry

The first thing we can notice to make our circle drawing algorithm more efficient is that circles centred at (0, 0) have eight-way symmetry

April 21, 2023 10

Page 11: November 18, 20151. We could solve for y in terms of x ( x 0, y 0 ) are the origin points A Simple Circle Drawing Algorithm The equation for a circle

Mid-Point Circle Algorithm

Similarly to the case with lines, there is an incremental algorithm for drawing circles – the mid-point circle algorithmIn the mid-point circle algorithm we use eight-way symmetry so only ever calculate the points for the top right eighth of a circle, and then use symmetry to get the rest of the points

Assume that we have just plotted point (xk, yk)The next point is a choice between (xk+1, yk) and (xk+1, yk-1)We would like to choose the point that is nearest to the actual circleSo how do we make this choice?

April 21, 2023 11

Page 12: November 18, 20151. We could solve for y in terms of x ( x 0, y 0 ) are the origin points A Simple Circle Drawing Algorithm The equation for a circle

April 21, 2023 12

Note: When x-axis increased by one unit, then the y-axis either increased by one or not

Page 13: November 18, 20151. We could solve for y in terms of x ( x 0, y 0 ) are the origin points A Simple Circle Drawing Algorithm The equation for a circle

Assuming we have just plotted the pixel at (xk,yk) so we need to choose between (xk+1,yk) ( A), or (xk+1,yk-1) (B)... By comparing distance between points and the real circle line.

dA = (xk + 1)2 + yk2 – r2

dB = (xk + 1)2 + (yk -1)2 – r2

Now check the point with smallest distance, by checking the sum of (dA, and dB)

S = dA + dB

What are the probabilities of S value?

April 21, 2023 13

Page 14: November 18, 20151. We could solve for y in terms of x ( x 0, y 0 ) are the origin points A Simple Circle Drawing Algorithm The equation for a circle

1. Line between A and B

dA > 0 and dB < 0

If abs (dA) > abs (dB) S >0 choose B

If abs (dA) <= abs (dB) S<= 0 choose A

2. If the circle line pass through or up of A

dA <= 0 and dB < 0

S < 0 choose A

3. If the circle line pass through or under the point B

dA > 0 and dB >= 0

S > 0 choose B

April 21, 2023 14

Page 15: November 18, 20151. We could solve for y in terms of x ( x 0, y 0 ) are the origin points A Simple Circle Drawing Algorithm The equation for a circle

RULE

If S >0 choose pixel B

Else choose A

April 21, 2023 15

Page 16: November 18, 20151. We could solve for y in terms of x ( x 0, y 0 ) are the origin points A Simple Circle Drawing Algorithm The equation for a circle

Ellipses

x = a . cos (ө) OR x = xc + a . cos (ө)

y = b . sin(ө) OR y = yc + b . sin(ө)

April 21, 2023 16

Page 17: November 18, 20151. We could solve for y in terms of x ( x 0, y 0 ) are the origin points A Simple Circle Drawing Algorithm The equation for a circle

To draw ellipse:

1.The ellipse has four points symmetry2.Increment angle with very small value (dө)3.Find (x2, y2) from point (x1, y1)4.Find (x2, y2) according to the following equations

x2 = x1 . cos (dө) – (a/b) . y1 . sin (dө)

y2 = y1 . cos (dө) + (b/a) . x1 . sin (dө)

The start point will be (0, a)

Ending of loop when x = b

April 21, 2023 17

Page 18: November 18, 20151. We could solve for y in terms of x ( x 0, y 0 ) are the origin points A Simple Circle Drawing Algorithm The equation for a circle

Home work / draw the following figure

April 21, 2023 18

Page 19: November 18, 20151. We could solve for y in terms of x ( x 0, y 0 ) are the origin points A Simple Circle Drawing Algorithm The equation for a circle

Home work / draw the following figure

April 21, 2023 19


Recommended