Skip to main content

Ellipse symmetry and drawing algorithm

Short answer

An ellipse has four-way symmetry about the axes, so computing only the first quadrant yields four pixels per point, reducing work. The midpoint ellipse algorithm splits the quadrant at slope -1: region 1 steps x, uses p1=ry²−rx²·ry+rx²/4; region 2 steps y, initial p2=ry²(x+0.5)²+rx²(y−1)²−rx²ry², then plots (±x,±y) shifted to center.

How is the symmetric property vital while drawing an ellipse? Write an algorithm to draw an ellipse in raster graphics system.

Symmetry in ellipse drawing

An ellipse centred at the origin is symmetric about the x-axis and the y-axis. So if (x, y) is a point on the ellipse, then (−x, y), (x, −y) and (−x, −y) are also on it. This four-way symmetry means only the first quadrant needs to be calculated, and every calculated point gives 4 pixels, reducing the computation to one fourth. (Unlike a circle, an ellipse has no symmetry about y = x.)

Midpoint ellipse algorithm (rx, ry, centre (xc, yc))

The first quadrant is divided into region 1 (slope magnitude < 1, x is the unit step) and region 2 (slope magnitude ≥ 1, y is the unit step). The boundary is where 2ry²x = 2rx²y. The ellipse function f(x, y) = ry²x² + rx²y² − rx²ry² is tested at the midpoint of the two candidate pixels.

Input rx, ry and centre (xc, yc).
Region 1 (slope magnitude < 1):
  x = 0, y = ry
  p1 = ry² − rx²·ry + rx²/4
  while 2·ry²·x < 2·rx²·y:
      plot the 4 symmetric points of (x, y)
      x = x + 1
      if p1 < 0:
          p1 = p1 + 2·ry²·x + ry²
      else:
          y = y − 1
          p1 = p1 + 2·ry²·x − 2·rx²·y + ry²
Region 2 (slope magnitude ≥ 1), start from last (x, y):
  p2 = ry²(x + ½)² + rx²(y − 1)² − rx²·ry²
  while y ≥ 0:
      plot the 4 symmetric points of (x, y)
      y = y − 1
      if p2 > 0:
          p2 = p2 − 2·rx²·y + rx²
      else:
          x = x + 1
          p2 = p2 + 2·ry²·x − 2·rx²·y + rx²
Each plotted point is shifted by (xc, yc): (xc±x, yc±y).

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Graphics chapter 2 questions →