C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Bresenham's Circle Algorithm:Scan-Converting a circle using Bresenham's algorithm works as follows: Points are generated from 90° to 45°, moves will be made only in the +x & -y directions as shown in fig: The best approximation of the true circle will be described by those pixels in the raster that falls the least distance from the true circle. We want to generate the points from 90° to 45°. Assume that the last scan-converted pixel is P1 as shown in fig. Each new point closest to the true circle can be found by taking either of two actions.
Let D (Si) is the distance from the origin to the true circle squared minus the distance to point P3 squared. D (Ti) is the distance from the origin to the true circle squared minus the distance to point P2 squared. Therefore, the following expressions arise. D (Si)=(xi-1+1)2+ yi-12 -r2 Since D (Si) will always be +ve & D (Ti) will always be -ve, a decision variable d may be defined as follows: di=D (Si )+ D (Ti) Therefore, From this equation, we can drive initial values of di as If it is assumed that the circle is centered at the origin, then at the first step x = 0 & y = r. Therefore, Thereafter, if d_i<0,then only x is incremented. xi+1=xi+1 di+1=di+ 4xi+6 & if di≥0,then x & y are incremented Bresenham's Circle Algorithm:Step1: Start Algorithm Step2: Declare p, q, x, y, r, d variables Step3: Enter the value of r Step4: Calculate d = 3 - 2r Step5: Initialize x=0 Step6: Check if the whole circle is scan converted Step7: Plot eight points by using concepts of eight-way symmetry. The center is at (p, q). Current active pixel is (x, y). Step8: Find location of next pixels to be scanned Step9: Go to step 6 Step10: Stop Algorithm Example: Plot 6 points of circle using Bresenham Algorithm. When radius of circle is 10 units. The circle has centre (50, 50). Solution: Let r = 10 (Given) Step1: Take initial point (0, 10) Step2: Plot (1, 10) Step3: Plot (2, 10) Step4: Plot (3, 9) d is > 0 so x = x + 1, y = y - 1 Step5: Plot (4, 9) Step6: Plot (5, 8) So P1 (0,0)⟹(50,50) Program to draw a circle using Bresenham's circle drawing algorithm:#include Output:
Next TopicMidpoint Circle Algorithm
|