0% found this document useful (0 votes)
22 views5 pages

CG - Study - Material Unit 1 & 2-29-33

The document discusses methods for generating graphics primitives, particularly focusing on circle and ellipse drawing algorithms. It explains the use of polar coordinates and symmetry properties to efficiently compute pixel positions for circles, as well as the Midpoint Circle Algorithm and its decision parameters. Additionally, it introduces the definition and properties of ellipses, including their mathematical representation based on distances from fixed foci.

Uploaded by

Somnath Gunjal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views5 pages

CG - Study - Material Unit 1 & 2-29-33

The document discusses methods for generating graphics primitives, particularly focusing on circle and ellipse drawing algorithms. It explains the use of polar coordinates and symmetry properties to efficiently compute pixel positions for circles, as well as the Midpoint Circle Algorithm and its decision parameters. Additionally, it introduces the definition and properties of ellipses, including their mathematical representation based on distances from fixed foci.

Uploaded by

Somnath Gunjal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Unit-2 – Graphics Primitives

 We can adjust spacing by stepping through 𝑦 values and calculating 𝑥 values whenever the absolute
value of the slop of the circle is greater than 1. But it will increases computation processing requirement.
 Another way to eliminate the non-uniform spacing is to draw circle using polar coordinates ‘𝑟’ and ‘ ’.
 Calculating circle boundary using polar equation is given by pair of equations which is as follows.
𝑥 = 𝑥𝑐 + 𝑟 cos 
𝑦 = 𝑦𝑐 + 𝑟 sin 
 When display is produce using these equations using fixed angular step size circle is plotted with uniform
spacing.
 The step size ‘ ’ is chosen according to application and display device.
 For a more continuous boundary on a raster display we can set the step size at 1/𝑟. This plot pixel
position that are approximately one unit apart.
 Computation can be reduced by considering symmetry city property of circles. The shape of circle is
similar in each quadrant.
 We can obtain pixel position in second quadrant from first quadrant using reflection about 𝑦 axis and
similarly for third and fourth quadrant from second and first respectively using reflection about 𝑥 axis.
 We can take one step further and note that there is also symmetry between octants. Circle sections in
adjacent octant within one quadrant are symmetric with respect to the 450 line dividing the two
octants.
 This symmetry condition is shown in figure below where point (𝑥, 𝑦) on one circle sector is mapped in
other seven sector of circle.

(-Y, X) (Y, X)

45O
(-X, Y)
(X, Y)

(-X, -Y) (X, -Y)

(-Y, -X) (Y, -X)


Fig. 2.9: - symmetry of circle.
 Taking advantage of this symmetry property of circle we can generate all pixel position on boundary of
circle by calculating only one sector from 𝑥 = 0 to 𝑥 = 𝑦.
 Determining pixel position along circumference of circle using any of two equations shown above still
required large computation.
 More efficient circle algorithm are based on incremental calculation of decision parameters, as in the
Bresenham line algorithm.
 Bresenham’s line algorithm can be adapted to circle generation by setting decision parameter for finding
closest pixel to the circumference at each sampling step.
 The Cartesian coordinate circle equation is nonlinear so that square root evaluations would be required
to compute pixel distance from circular path.
 Bresenham’s circle algorithm avoids these square root calculation by comparing the square of the pixel
separation distance.

9
Unit-2 – Graphics Primitives
 A method for direct distance comparison to test the midpoint between two pixels to determine if this
midpoint is inside or outside the circle boundary.
 This method is easily applied to other conics also.
 Midpoint approach generates same pixel position as generated by bresenham’s circle algorithm.
 The error involve in locating pixel positions along any conic section using midpoint test is limited to one-
half the pixel separation.

Midpoint Circle Algorithm


 Similar to raster line algorithm we sample at unit interval and determine the closest pixel position to the
specified circle path at each step.
 Given radius ‘𝑟’ and center (𝑥𝑐, 𝑦𝑐)
 We first setup our algorithm to calculate circular path coordinates for center (0, 0). And then we will
transfer calculated pixel position to center (𝑥𝑐, 𝑦𝑐) by adding 𝑥𝑐 to 𝑥 and 𝑦𝑐 to 𝑦.
 Along the circle section from 𝑥 = 0 to 𝑥 = 𝑦 in the first quadrant, the slope of the curve varies from 0
to -1 so we can step unit step in positive 𝑥 direction over this octant and use a decision parameter to
determine which of the two possible 𝑦 position is closer to the circular path.
 Position in the other seven octants are then obtain by symmetry.
 For the decision parameter we use the circle function which is:
𝑓𝑐𝑖𝑟𝑐𝑙𝑒(𝑥, 𝑦) = 𝑥2 + 𝑦2 − 𝑟2
 Any point which is on the boundary is satisfied 𝑓𝑐𝑖𝑟𝑐𝑙𝑒(𝑥, 𝑦) = 0 if the point is inside circle function value
is negative and if point is outside circle the function value is positive which can be summarize as below.
< 0 𝑖𝑓 (𝑥, 𝑦)𝑖𝑠 𝑖𝑛𝑠𝑖𝑑𝑒 𝑡ℎ𝑒 𝑐𝑖𝑟𝑐𝑙𝑒 𝑏𝑜𝑢𝑛𝑑𝑎𝑟𝑦
𝑓𝑐𝑖𝑟𝑐𝑙𝑒(𝑥, 𝑦) { = 0 𝑖𝑓 (𝑥, 𝑦)𝑖𝑠 𝑜𝑛 𝑡ℎ𝑒 𝑐𝑖𝑟𝑐𝑙𝑒 𝑏𝑜𝑢𝑛𝑑𝑎𝑟𝑦
> 0 𝑖𝑓 (𝑥, 𝑦)𝑖𝑠 𝑜𝑢𝑡𝑠𝑖𝑑𝑒 𝑡ℎ𝑒 𝑐𝑖𝑟𝑐𝑙𝑒 𝑏𝑜𝑢𝑛𝑑𝑎𝑟𝑦
 Above equation we calculate for the mid positions between pixels near the circular path at each
sampling step and we setup incremental calculation for this function as we did in the line algorithm.
 Below figure shows the midpoint between the two candidate pixels at sampling position 𝑥𝑘 + 1.

𝒙𝟐 + 𝒚𝟐 − 𝒓𝟐 = 𝟎

𝒚𝒌 Midpoint
𝒚𝒌 − 𝟏

𝒙𝒌 𝒙𝒌 + 𝟏 𝒙𝒌 + 𝟐

Fig. 2.10: - Midpoint between candidate pixel at sampling position 𝑥𝑘 + 1 along circle path.
 Assuming we have just plotted the pixel at (𝑥𝑘, 𝑦𝑘) and next we need to determine whether the pixel at
position ‘(𝑥𝑘 + 1, 𝑦𝑘)’ or the one at position’ (𝑥𝑘 + 1, 𝑦𝑘 − 1)’ is closer to circle boundary.
 So for finding which pixel is more closer using decision parameter evaluated at the midpoint between
two candidate pixels as below:
𝑝𝑘 = 𝑓𝑐𝑖𝑟𝑐𝑙𝑒 (𝑥𝑘 + 1, 𝑦𝑘 − 21)
( )2 1 2
𝑝𝑘 = 𝑥𝑘 + 1 + (𝑦 − ) − 𝑟 2
𝑘
2
 If 𝑝𝑘 < 0 this midpoint is inside the circle and the pixel on the scan line 𝑦𝑘 is closer to circle boundary.
Otherwise the midpoint is outside or on the boundary and we select the scan line 𝑦𝑘 − 1.
 Successive decision parameters are obtain using incremental calculations as follows:

10
Unit-2 – Graphics Primitives
1
𝑝𝑘+1 = 𝑓𝑐𝑖𝑟𝑐𝑙𝑒 (𝑥𝑘+1 + 1, 𝑦𝑘+1 − )
2
𝑝 = [(𝑥 + 1) + 1]2 + 𝑦 ( 1 2 2
𝑘+1 𝑘
𝑘+1 − 2
) −𝑟
 Now we can obtain recursive calculation using equation of 𝑝𝑘+1 and 𝑝𝑘 as follow.
𝑝 − 𝑝 = ([(𝑥 + 1) + 1]2 + 𝑦( 1 2 2 ( )2 1 2 2
𝑘+1 𝑘 𝑘 𝑘+1 − ) − 𝑟 ) − ( 𝑥𝑘 + 1 + (𝑦𝑘 − ) −𝑟 )
2 2
𝑝𝑘+1 − 𝑝𝑘 = (𝑥𝑘 + 1)2 + 2(𝑥𝑘 + 1) + 1 + 𝑦𝑘+12 − 𝑦𝑘+1 + 1 − 𝑟2 − (𝑥𝑘 + 1)2 − 𝑦𝑘2 + 𝑦𝑘 − 1 + 𝑟2
4 4
𝑝𝑘+1 − 𝑝𝑘 = 2(𝑥𝑘 + 1) + 1 + 𝑦𝑘+12 − 𝑦𝑘+1 − 𝑦𝑘2 + 𝑦𝑘
𝑝𝑘+1 − 𝑝𝑘 = 2(𝑥𝑘 + 1) + (𝑦𝑘+12 − 𝑦𝑘2) − (𝑦𝑘+1 − 𝑦𝑘) + 1
𝑝𝑘+1 = 𝑝𝑘 + 2(𝑥𝑘 + 1) + (𝑦𝑘+12 − 𝑦𝑘2) − (𝑦𝑘+1 − 𝑦𝑘) + 1
 In above equation 𝑦𝑘+1 is either 𝑦𝑘 or 𝑦𝑘 − 1 depending on the sign of the 𝑝𝑘.
 Now we can put 2𝑥𝑘+1 = 2𝑥𝑘 + 2 and when we select 𝑦𝑘+1 = 𝑦𝑘 − 1 we can obtain 2𝑦𝑘+1 = 2𝑦𝑘 − 2.
 The initial decision parameter is obtained by evaluating the circle function at the start position
(𝑥0, 𝑦0) = (0, 𝑟) as follows.
𝑝0 = 𝑓𝑐𝑖𝑟𝑐𝑙𝑒 (0 + 1, 𝑟 − 21)
2 1 2 2
𝑝0 = 1 + (𝑟 − 2) − 𝑟
𝑝0 = 1 + 𝑟2 − 𝑟 + 1 − 𝑟2
4
𝑝0 = 5 − 𝑟
4

Algorithm for Midpoint Circle Generation


1. Input radius 𝑟 and circle center (𝑥𝑐, 𝑦𝑐), and obtain the first point on the circumference of a circle
centered on the origin as
(𝑥0, 𝑦0) = (0, 𝑟)
2. calculate the initial value of the decision parameter as
𝑝0 = 5 − 𝑟
4
3. At each 𝑥𝑘 position, starting at 𝑘 = 0, perform the following test:
If 𝑝𝑘 < 0, the next point along the circle centered on (0, 0) is (𝑥𝑘 + 1, 𝑦𝑘) &
𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 + 1
Otherwise, the next point along the circle is (𝑥𝑘 + 1, 𝑦𝑘 − 1) &
𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 + 1 − 2𝑦𝑘+1
Where 2𝑥𝑘+1 = 2𝑥𝑘 + 2, & 2𝑦𝑘+1 = 2𝑦𝑘 − 2.
4. Determine symmetry points in the other seven octants.
5. Move each calculated pixel position (𝑥, 𝑦) onto the circular path centered on (𝑥𝑐, 𝑦𝑐) and plot the
coordinate values:
𝑥 = 𝑥 + 𝑥𝑐, 𝑦 = 𝑦 + 𝑦𝑐
6. Repeat steps 3 through 5 until 𝑥 ≥ 𝑦.

11
Unit-2 – Graphics Primitives
Ellipse

Fig. 2.11: - Ellipse generated about foci f1 and f2.


 AN ellipse is defined as the set of points such that the sum of the distances from two fixed positions
(foci) is same for all points.

Properties of Ellipse
 If we labeled distance from two foci to any point on ellipse boundary as 𝑑1 and 𝑑2 then the general
equation of an ellipse can be written as follow.
𝑑1 + 𝑑2 = 𝐶𝑜𝑛𝑠𝑡𝑎𝑛𝑡
 Expressing distance in terms of focal coordinates 𝑓1 = (𝑥1, 𝑦1) and 𝑓2 = (𝑥2, 𝑦2) we have
√(𝑥 − 𝑥1)2 + (𝑦 − 𝑦1)2 + √(𝑥 − 𝑥2)2 + (𝑦 − 𝑦2)2 = 𝐶𝑜𝑛𝑠𝑡𝑎𝑛𝑡
 An interactive method for specifying an ellipse in an arbitrary orientation is to input two foci and a point
on the ellipse boundary.
 With this three coordinates we can evaluate constant in equation:
 √(𝑥 − 𝑥1)2 + (𝑦 − 𝑦1)2 + √(𝑥 − 𝑥2)2 + (𝑦 − 𝑦2)2 = 𝐶𝑜𝑛𝑠𝑡𝑎𝑛𝑡
 We can also write this equation in the form
𝐴𝑥2 + 𝐵𝑦2 + 𝐶𝑥𝑦 + 𝐷𝑥 + 𝐸𝑦 + 𝐹 = 0
 Where the coefficients 𝐴, 𝐵, 𝐶, 𝐷, 𝐸, and 𝐹 are evaluated in terms of the focal coordinates and the
dimensions of the major and minor axes of the ellipse.
 Major axis of an ellipse is straight line segment passing through both foci and extends up to boundary on
both sides.
 The minor axis spans shortest dimension of ellipse, it bisect the major axis at right angle in two equal
half.
 Then coefficient in 𝐴𝑥2 + 𝐵𝑦2 + 𝐶𝑥𝑦 + 𝐷𝑥 + 𝐸𝑦 + 𝐹 = 0 can be evaluated and used to generate pixels
along the elliptical path.
 Ellipse equation are greatly simplified if we align major and minor axis with coordinate axes i.e. 𝑥 − 𝑎𝑥𝑖𝑠
and 𝑦 − 𝑎𝑥𝑖𝑠.
 We can say ellipse is in standard position if their major and minor axes are parallel to 𝑥 − 𝑎𝑥𝑖𝑠 and 𝑦 −
𝑎𝑥𝑖𝑠 which is shown in below figure.

12
Unit-2 – Graphics Primitives

Fig. 2.12: - Ellipse centered at (𝑥𝑐, 𝑦𝑐) with semi major axis 𝑟𝑥 and semi minor axis 𝑟𝑦 are parallel to
coordinate axis.
 Equation of ellipse shown in figure 2.12 can be written in terms of the ellipse center coordinates and
parameters 𝑟𝑥 and 𝑟𝑦 as.
𝑥 − 𝑥𝑐 2 𝑦 − 𝑦𝑐 2
( ) +( ) =1
𝑟𝑥 𝑟𝑦
 Using the polar coordinates 𝑟 and 𝜃, we can also describe the ellipse in standard position with the
parametric equations:
𝑥 = 𝑥𝑐 + 𝑟𝑥 cos θ
𝑦 = 𝑦𝑐 + 𝑟𝑦 sin θ
 Symmetry considerations can be used to further reduced computations.
 An ellipse in standard position is symmetric between quadrants but unlike a circle it is not symmetric
between octant.
 Thus we must calculate boundary point for one quadrant and then other three quadrants point can be
obtained by symmetry as shown in figure below.

(−𝑥, 𝑦) (𝑥, 𝑦)
𝑟𝑦
𝑟𝑥
(𝑥𝑐, 𝑦𝑐)

(−𝑥, − 𝑦) (𝑥, − 𝑦)

Fig. 2.13: - symmetry of an ellipse.

Midpoint Ellipse Algorithm


 Midpoint ellipse algorithm is a method for drawing ellipses in computer graphics. This method is
modified from Bresenham's algorithm.

13

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy