# Graphics Problems

Graphics problems typically focus on your ability to implement primitive graphics functions rather than using a high-level API as you would in most programming projects.

## Eighth of a Circle

**PROBLEM**Write a function that draws the upper-eighth of a circle centered at (0, 0) with a given radius, where the upper-eighth is defined as the portion starting at 12 and going to 1:30 on a clock face. Use the following prototype:

`void drawEighthOfCircle( int radius );`

`void setPixel( int xCoord, int yCoord );`

This problem is not as contrived as it seems. If you were trying to implement a full-circle drawing routine, you would want to do as little calculation as possible to maintain optimum performance. Given the pixels for one-eighth of a circle, you can easily determine the pixels for the remainder of the circle from symmetry.

**NOTE**If a point (x, y) is on a circle, so are the points (âx, y), (x, ây), (âx, ây), (y, x), (ây, x), (y, âx), and (ây, âx).

This problem is an example of a scan conversion, converting a geometric drawing to a pixel-based raster image. You need an equation for a circle before you can calculate anything. The common mathematical function that produces a ...

Get *Programming Interviews Exposed: Secrets to Landing Your Next Job, 3rd Edition* now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.