# VITS CSE1 MIDPOINT CIRCLE & ELLIPSE GENERARTING ALGORITHMS Circle Generating Algorithm Properties of circle Midpoint circle algorithm Ellipse-generating

• Published on
05-Jan-2016

• View
215

0

Embed Size (px)

Transcript

• MIDPOINT CIRCLE & ELLIPSE GENERARTING ALGORITHMS

Circle Generating AlgorithmProperties of circleMidpoint circle algorithm

Ellipse-generating algorithmProperties of ellipseMidpoint ellipse algorithm

VITS CSE

• Circle Generating AlgorithmProperties of Circle

Circle is defined as the set of points that are all at a given distance r from a center point (xc,yc)

For any circle point (x,y), the distance relationship is expressed by the Pythagorean theorem in Cartesian coordinate as:

VITS CSE

• Circle Generating AlgorithmWe could use this equation to calculate the points on a circle circumference by stepping along x-axis in unit steps from xcr to xc+r and calculate the corresponding y values as

VITS CSE

• Circle Generating AlgorithmThe problems:Involves many computation at each stepi.e., square root and additions /subtractionsSpacing between plotted pixel positions is not uniformAdjustment: interchanging x & y (step through y values and calculate x values)Involves many computation too!

VITS CSE

• Circle Generating AlgorithmAnother way:Calculate points along a circular boundary using polar coordinates r and x = xc + r cos y = yc + r sin

Using fixed angular step size, a circle is plotted with equally spaced points along the circumference

Problem: trigonometric calculations are still time consuming

VITS CSE

• Symmetry of Circles (8-way symmetry)Proposed Approach:symmetry of circles

Shape of the circle is similar in each quadrant

i.e. if we determine the curve positions in the 1st quadrant, we can generate the circle section in the 2nd quadrant of the xy plane (the 2 circle sections are symmetric with respect to the y axis)

The circle section in the 3rd and 4th quadrant can be obtained by considering symmetry about the x axis

One step further symmetry between octants

VITS CSE

• 8-way symmetryCircle sections in adjacent octants within 1 quadrant are symmetric with respect to the 45 line dividing the 2 octants

Calculation of a circle point (x, y) in 1 octant yields the circle points for the other 7 octants

VITS CSE

• Midpoint Circle AlgorithmAs in raster algorithm, we sample at unit intervals & determine the closest pixel position to the specified circle path at each step

For a given radius, r and screen center position (xc,yc) , we can set up our algorithm to calculate pixel positions around a circle path centered at the coordinate origin (0,0)

Each calculated position (x, y) is moved to its proper screen position by adding xc to x and yc to y

VITS CSE

• Midpoint Circle AlgorithmAlong a circle section from x=0 to x=y in the 1st quadrant, the slope (m) of the curve varies from 0 to -1.0

i.e. we can take unit steps in the +ve x direction over the octant & use decision parameter to determine which 2 possible positions is vertically closer to the circle path

Positions in the other 7 octants are obtained by symmetry

VITS CSE

• Midpoint Circle AlgorithmTo apply the midpoint method, we define a circle function asfcirc(x,y) = x2 + y2 - r2

The relative positions of any point (x,y) can be determined by checking the sign of the circle function:

< 0, if (x,y) is inside the circle boundaryfcirc(x,y) = 0, if (x,y) is on the circle boundary > 0, if (x,y) is outside the circle boundary

VITS CSE

• Midpoint Circle AlgorithmConsider current position (xk, yk) next pixel position is either(xk+1, yk) or (xk+1, yk-1)?

VITS CSE

• Midpoint Circle AlgorithmOur decision parameter is the earlier circle function evaluated at the mid point between the 2 pixels

< 0: midpoint is inside the circle; plot (xk+1, yk) +ve: midpoint is outside the circle; plot (xk+1, yk-1)

Successive decision parameters are obtained using incremental calculation

pk

VITS CSE

• Midpoint Circle AlgorithmTo ensure things are as efficient as possible we can do all of our calculations incrementallyFirst consider:

or

where yk+1 is either yk or yk-1 depending on the sign of pk

VITS CSE

• Midpoint Circle AlgorithmInitial decision parameter is obtained by evaluating the circle function at the start position (x0, y0) = (0,r)p0 = f(1, r1/2) = 12 + (r 1/2)2 r2 p0 = 5/4 rIf the radius is specified as an integer, we can simple round p0 to p0 = 1 r Then if pk < 0 then the next decision variable is given as:

If pk > 0 then the decision variable is:

VITS CSE

• Midpoint Circle AlgorithmInput radius, r, and circle center (xc, yc), then set the coordinates for the 1st point on the circumference of a circle centered at the origin as (x0, y0) = (0,r)

Calculate initial value of decision parameter:

At each xk, starting at k = 0, test the value of pk : If pk < 0, next point will be (xk+1, yk) and else, next point will be (xk+1, yk 1) and where 2xk+1 = 2xk + 2 and 2yk+1 = 2yk 2

Determine symmetry points in the other 7 octants.

Get the actual point for circle centered at (xc,yc) that is (x+xc, y+yc).

Repeat step 3 to 5 until x y.

VITS CSE

• Try this out!Given a circle radius r=10, demonstrate the midpoint circle algorithm by determining positions along the circle octant in the 1st quadrant

p0 = ?(x0,y0) = ?

VITS CSE

• Plot pixel positions

109876543210012345678910

VITS CSE

• Try this again!Given a circle with r=8, calculate each pixel positions along the circumference at the 2nd quadrant

VITS CSE

• Ellipse Generating AlgorithmEllipse an elongated circle.

A modified circle whose radius varies from a maximum value in one direction to a minimum value in the perpendicular direction.A precise definition in terms of distance from any point on the ellipse to two fixed position, called the foci of the ellipse.

The sum of these two distances is the same value for all points on the ellipse.

VITS CSE

• Ellipse Generating AlgorithmIf the distance of the two focus positions from any point P=(x, y) on the ellipse are labeled d1 and d2, the general equation of an ellipse:

d1 + d2 = constant

Expressing distance d1 and d2 in terms of the focal coordinates F1=(x1, y1) and F2=(x2, y2), we have

VITS CSE

• Ellipse Generating AlgorithmHowever, we will only consider standard ellipse:

VITS CSE

• 2-way symmetryAn ellipse only has a 2-way symmetry.

VITS CSE

• Equation of an ellipseConsider an ellipse centered at the origin, (xc,yc)=(0,0):

Ellipse function

and its properties: fellipse(x,y) < 0 if (x,y) is inside the ellipse fellipse(x,y) = 0 if (x,y) is on the ellipse fellipse(x,y) > 0 if (x,y) is outside the ellipse

VITS CSE

• Midpoint Ellipse AlgorithmEllipse is different from circle.Similar approach with circle, different in sampling direction.Slope of ellipse is: dy/dx = - 2ry2x/2rx2yRegion 1:Sampling is at x directionChoose between (xk+1, yk), or (xk+1, yk-1) Move of region 1 if 2r2yx >= 2r2xyRegion 2:Sampling is at y directionChoose between (xk, yk-1), or (xk+1, yk-1)ryrx

VITS CSE

• Decision parametersRegion 1:Decision parameter

p1k < 0:midpoint is insidechoose pixel (xk+1, yk)p1k >= 0:midpoint is outside/onchoose pixel (xk+1, yk-1)

Region 2:Decision parameter

p2k 0:midpoint is outsidechoose pixel (xk, yk-1)

VITS CSE

• Midpoint Ellipse AlgorithmInput rx, ry and ellipse center (xc, yc). Obtain the first point on an ellipse centered on the origin (x0, y0) = (0, ry).

Calculate initial value for decision parameter in region 1 as:

At each xk in region 1, starting from k = 0, test p1k :

If p1k < 0, next point (xk+1, yk) and

else, next point (xk+1, yk-1) and

with 2ry2xk+1 = 2ry2xk + 2ry2, 2rx2yk+1 = 2rx2yk 2rx2

and repeat step 1 to 3 until 2ry2x 2rx2y

VITS CSE

• Midpoint Ellipse AlgorithmInitial value for decision parameter in region 2:

where (x0, y0) is the last position calculate in region 1

5.At each yk in region 2, starting from k = 0, test p2k:

If p2k > 0, next point is (xk, yk-1) and else, next point is (xk+1, yk-1) and continue until y=0

VITS CSE

• Midpoint Ellipse AlgorithmFor both region determine symmetry points in the other 3 quadrants

Move each calculated pixel position (x,y) onto the elliptical path centered on (xc,yc) and plot the coordinate values x=x + xc, y =y + yc

VITS CSE

• Try this out!Given input ellipse parameter rx=8 and ry=6, determine pixel positions along the ellipse path in the first quadrant using the midpoint ellipse algorithm

2ry2x = ?2rx2y = 2rx2ry = ?p10 = ? We now move out from R1 since2ry2 x> 2 rx2y For R2,initial point is(xo,yo)=(7,3)& p2o=f(7+1/2,2)=-151

kp2k(xk+1,yk+1)2rv2 xk+12 rx2yk+10-151(8,2)5762561233(8,1)5761282745(8,0)----

VITS CSE

• Plot pixel positions

6543210012345678

VITS CSE